def sort(self, by: str, out: object='', **kwargs) -> 'SASdata':
    "\n        Sort the SAS Data Set\n\n        :param by: REQUIRED variable to sort by (BY <DESCENDING> variable-1 <<DESCENDING> variable-2 ...>;)\n        :param out: OPTIONAL takes either a string 'libref.table' or 'table' which will go to WORK or USER\n            if assigned or a sas data object'' will sort in place if allowed\n        :param kwargs:\n        :return: SASdata object if out= not specified, or a new SASdata object for out= when specified\n\n        :Example:\n\n        #. wkcars.sort('type')\n        #. wkcars2 = sas.sasdata('cars2')\n        #. wkcars.sort('cylinders', wkcars2)\n        #. cars2=cars.sort('DESCENDING origin', out='foobar')\n        #. cars.sort('type').head()\n        #. stat_results = stat.reg(model='horsepower = Cylinders EngineSize', by='type', data=wkcars.sort('type'))\n        #. stat_results2 = stat.reg(model='horsepower = Cylinders EngineSize', by='type', data=wkcars.sort('type','work.cars'))\n        "
    outstr = ''
    options = ''
    if out:
        if isinstance(out, str):
            fn = out.partition('.')
            if (fn[1] == '.'):
                libref = fn[0]
                table = fn[2]
                outstr = ('out=%s.%s' % (libref, table))
            else:
                libref = ''
                table = fn[0]
                outstr = ('out=' + table)
        else:
            libref = out.libref
            table = out.table
            outstr = ('out=%s.%s' % (out.libref, out.table))
    if ('options' in kwargs):
        options = kwargs['options']
    code = ('proc sort data=%s.%s%s %s %s ;\n' % (self.libref, self.table, self._dsopts(), outstr, options))
    code += ('by %s;' % by)
    code += 'run\n;'
    runcode = True
    if self.sas.nosub:
        print(code)
        runcode = False
    ll = self._is_valid()
    if ll:
        runcode = False
    if runcode:
        ll = self.sas.submit(code, 'text')
        elog = []
        for line in ll['LOG'].splitlines():
            if line[self.sas.logoffset:].startswith('ERROR'):
                elog.append(line)
        if len(elog):
            raise RuntimeError('\n'.join(elog))
    if out:
        if (not isinstance(out, str)):
            return out
        else:
            return self.sas.sasdata(table, libref, self.results)
    else:
        return self
Sort the SAS Data Set

:param by: REQUIRED variable to sort by (BY <DESCENDING> variable-1 <<DESCENDING> variable-2 ...>;)
:param out: OPTIONAL takes either a string 'libref.table' or 'table' which will go to WORK or USER
    if assigned or a sas data object'' will sort in place if allowed
:param kwargs:
:return: SASdata object if out= not specified, or a new SASdata object for out= when specified

:Example:

#. wkcars.sort('type')
#. wkcars2 = sas.sasdata('cars2')
#. wkcars.sort('cylinders', wkcars2)
#. cars2=cars.sort('DESCENDING origin', out='foobar')
#. cars.sort('type').head()
#. stat_results = stat.reg(model='horsepower = Cylinders EngineSize', by='type', data=wkcars.sort('type'))
#. stat_results2 = stat.reg(model='horsepower = Cylinders EngineSize', by='type', data=wkcars.sort('type','work.cars'))
def sort(self, by: str, out: object=, **kwargs) -> 'SASdata':
    "\n        Sort the SAS Data Set\n\n        :param by: REQUIRED variable to sort by (BY <DESCENDING> variable-1 <<DESCENDING> variable-2 ...>;)\n        :param out: OPTIONAL takes either a string 'libref.table' or 'table' which will go to WORK or USER\n            if assigned or a sas data object will sort in place if allowed\n        :param kwargs:\n        :return: SASdata object if out= not specified, or a new SASdata object for out= when specified\n\n        :Example:\n\n        #. wkcars.sort('type')\n        #. wkcars2 = sas.sasdata('cars2')\n        #. wkcars.sort('cylinders', wkcars2)\n        #. cars2=cars.sort('DESCENDING origin', out='foobar')\n        #. cars.sort('type').head()\n        #. stat_results = stat.reg(model='horsepower = Cylinders EngineSize', by='type', data=wkcars.sort('type'))\n        #. stat_results2 = stat.reg(model='horsepower = Cylinders EngineSize', by='type', data=wkcars.sort('type','work.cars'))\n        "
    outstr = 
    options = 
    if out:
        if isinstance(out, str):
            fn = out.partition('.')
            if (fn[1] == '.'):
                libref = fn[0]
                table = fn[2]
                outstr = ('out=%s.%s' % (libref, table))
            else:
                libref = 
                table = fn[0]
                outstr = ('out=' + table)
        else:
            libref = out.libref
            table = out.table
            outstr = ('out=%s.%s' % (out.libref, out.table))
    if ('options' in kwargs):
        options = kwargs['options']
    code = ('proc sort data=%s.%s%s %s %s ;\n' % (self.libref, self.table, self._dsopts(), outstr, options))
    code += ('by %s;' % by)
    code += 'run\n;'
    runcode = True
    if self.sas.nosub:
        print(code)
        runcode = False
    ll = self._is_valid()
    if ll:
        runcode = False
    if runcode:
        ll = self.sas.submit(code, 'text')
        elog = []
        for line in ll['LOG'].splitlines():
            if line[self.sas.logoffset:].startswith('ERROR'):
                elog.append(line)
        if len(elog):
            raise RuntimeError('\n'.join(elog))
    if out:
        if (not isinstance(out, str)):
            return out
        else:
            return self.sas.sasdata(table, libref, self.results)
    else:
        return self