How to use the saspy.sasdata.SASdata function in saspy

To help you get started, we’ve selected a few saspy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sassoftware / saspy / saspy / sasbase.py View on Github external
:param file: either the OS filesystem path of the file, or HTTP://... for a url accessible file
        :param table: the name of the SAS Data Set to create
        :param libref: the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned
        :param results: format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives
        :param opts: a dictionary containing any of the following Proc Import options(datarow, delimiter, getnames, guessingrows)
        :return: SASdata object
        """
        opts = opts if opts is not None else {}

        if results == '':
            results = self.results

        self._io.read_csv(file, table, libref, self.nosub, opts)

        if self.exist(table, libref):
            return SASdata(self, libref, table, results)
        else:
            return None
github sassoftware / saspy / saspy / sasdata.py View on Github external
def where(self, where: str) -> 'SASdata':
        """
        This method returns a clone of the SASdata object, with the where attribute set. The original SASdata object is not affected.

        :param where: the where clause to apply
        :return: SAS data object
        """
        sd = SASdata(self.sas, self.libref, self.table, dsopts=dict(self.dsopts))
        sd.HTML = self.HTML
        sd.dsopts['where'] = where
        return sd
github sassoftware / saspy / saspy / sasproccommons.py View on Github external
if contantValues is not None:
                        if not all(isinstance(x, tuple) for x in contantValues):
                            raise SyntaxError("The elements in the 'value' key must be tuples")
                        for t in contantValues:
                            tup_code += "impute %s / value = %s;\n" % (t[0], t[1])
                            usedVars.append(t[0])
                    meth_code = ''
                    for key, values in self._args.items():
                        for v in values:
                            meth_code += 'impute %s / method = %s;\n' % (v, key)
                            usedVars.append(v)
                    return '\ninput ' + ' '.join(list(set(usedVars))) + ';\n' + tup_code + meth_code + 'run;'

                print("KeyError: Proper keys not found for {} dictionary: {}".format(self._key, args))

        elif isinstance(self._args, SASdata):
            key = "{} =".format(self._key)
            args = "{}.'{}'n".format(self._args.libref, self._args.table)
            if self._key in ['out','output']:
                return "output out={}.'{}'n\n;".format(self._args.libref, self._args.table)
            if self._key == 'score':
                if self.objtype.casefold() == 'hp4score':
                    return "score out={}.'{}'n\n;".format(self._args.libref, self._args.table)
                elif self.objtype.casefold() == 'tpspline':
                    return "score data={0}.'{1}'n out={2}.'{3}'n\n;".format(self.data.libref, self.data.table, self._args.libref, self._args.table)
                return "score out={}.'{}'n\n;".format(self._args.libref, self._args.table)
            elif self._key == 'savestate':
                return "{} rstore = {}.'{}'n\n;".format(key, self._args.libref, self._args.table)
            elif self._key in ['output', 'out']:
                if len(self.outmeth):
                    return "{} out = {};\n".format(self._key, args)
                return "{}.'{}'n".format(self._args.libref, self._args.table)
github sassoftware / saspy / saspy / sasdata.py View on Github external
SAS assignment expressions.
        :param out: OPTIONAL takes a SASdata Object you create ahead of time. If not specified, replaces the existing table
               and the current SAS data object still refers to the replacement table.
        :param kwargs:
        :return: SAS Log showing what happened

        :Example:

        #. cars   = sas.sasdata('cars', 'sashelp') 
        #. wkcars = sas.sasdata('cars') 
        #. cars.add_vars({'PW_ratio': 'weight / horsepower', 'Overhang' : 'length - wheelbase'}, wkcars)
        #. wkcars.head()
        """

        if out is not None:
           if not isinstance(out, SASdata):
              print("out= needs to be a SASdata object")
              return None
           else:
              outtab = out.libref + ".'" + out.table + "'n " + out._dsopts() 
        else:
           outtab = self.libref + ".'" + self.table + "'n " + self._dsopts() 

        code  = "data "+outtab+"; set " + self.libref + ".'" + self.table + "'n " + self._dsopts() + ";\n"
        for key in vars.keys():
           code += key+" = "+vars[key]+";\n"
        code += "; run;"

        if self.sas.nosub:
            print(code)
            return
github sassoftware / saspy / saspy / sasbase.py View on Github external
if libref != '':
           if libref.upper() not in self.assigned_librefs():
              print("The libref specified is not assigned in this SAS Session.")
              return None

        if results == '':
            results = self.results
        if self.nosub:
            print("too complicated to show the code, read the source :), sorry.")
            return None
        else:
            self._io.dataframe2sasdata(df, table, libref, keep_outer_quotes, embedded_newlines, LF, CR, colsep)

        if self.exist(table, libref):
            return SASdata(self, libref, table, results)
        else:
            return None
github sassoftware / saspy / saspy / sasbase.py View on Github external
{'where'    : 'msrp < 20000 and make = "Ford"'
                              'keep'     : 'msrp enginesize Cylinders Horsepower Weight'
                              'drop'     : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight']
                              'obs'      :  10
                              'firstobs' : '12'
                              'format'  : {'money': 'dollar10', 'time': 'tod5.'}
                             }

        :return: SASdata object
        """
        dsopts = dsopts if dsopts is not None else {}

        if results == '':
            results = self.results
        sd = SASdata(self, libref, table, results, dsopts)
        if not self.exist(sd.table, sd.libref):
            if not self.batch:
                print(
                    "Table " + sd.libref + '.' + sd.table + " does not exist. This SASdata object will not be useful until the data set is created.")
        return sd