def sort(self, by: str, out: object = '<STR_LIT>', **kwargs) -> '<STR_LIT>':
outstr = '<STR_LIT>'<EOL>options = '<STR_LIT>'<EOL>if out:<EOL><INDENT>if isinstance(out, str):<EOL><INDENT>fn = out.partition('<STR_LIT:.>')<EOL>if fn[<NUM_LIT:1>] == '<STR_LIT:.>':<EOL><INDENT>libref = fn[<NUM_LIT:0>]<EOL>table = fn[<NUM_LIT:2>]<EOL>outstr = "<STR_LIT>" % (libref, table)<EOL><DEDENT>else:<EOL><INDENT>libref = '<STR_LIT>'<EOL>table = fn[<NUM_LIT:0>]<EOL>outstr = "<STR_LIT>" + table<EOL><DEDENT><DEDENT>else:<EOL><INDENT>libref = out.libref<EOL>table = out.table<EOL>outstr = "<STR_LIT>" % (out.libref, out.table)<EOL><DEDENT><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>options = kwargs['<STR_LIT>']<EOL><DEDENT>code = "<STR_LIT>" % (self.libref, self.table, self._dsopts(), outstr, options)<EOL>code += "<STR_LIT>" % by<EOL>code += "<STR_LIT>"<EOL>runcode = True<EOL>if self.sas.nosub:<EOL><INDENT>print(code)<EOL>runcode = False<EOL><DEDENT>ll = self._is_valid()<EOL>if ll:<EOL><INDENT>runcode = False<EOL><DEDENT>if runcode:<EOL><INDENT>ll = self.sas.submit(code, "<STR_LIT:text>")<EOL>elog = []<EOL>for line in ll['<STR_LIT>'].splitlines():<EOL><INDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>elog.append(line)<EOL><DEDENT><DEDENT>if len(elog):<EOL><INDENT>raise RuntimeError("<STR_LIT:\n>".join(elog))<EOL><DEDENT><DEDENT>if out:<EOL><INDENT>if not isinstance(out, str):<EOL><INDENT>return out<EOL><DEDENT>else:<EOL><INDENT>return self.sas.sasdata(table, libref, self.results)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return self<EOL><DEDENT>
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'))