nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, type; 5, block; 6, identifier:self; 7, typed_parameter; 8, typed_default_parameter; 9, dictionary_splat_pattern; 10, string; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, if_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, if_statement; 21, expression_statement; 22, if_statement; 23, if_statement; 24, if_statement; 25, identifier:by; 26, type; 27, identifier:out; 28, type; 29, string; 30, identifier:kwargs; 31, string_content:SASdata; 32, comment:"""
          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'))
          """; 33, assignment; 34, assignment; 35, identifier:out; 36, block; 37, comparison_operator:'options' in kwargs; 38, block; 39, assignment; 40, augmented_assignment; 41, augmented_assignment; 42, assignment; 43, attribute; 44, block; 45, assignment; 46, identifier:ll; 47, block; 48, identifier:runcode; 49, block; 50, identifier:out; 51, block; 52, else_clause; 53, identifier:str; 54, identifier:object; 55, identifier:outstr; 56, string; 57, identifier:options; 58, string; 59, if_statement; 60, string; 61, identifier:kwargs; 62, expression_statement; 63, identifier:code; 64, binary_operator:"proc sort data=%s.%s%s %s %s ;\n" % (self.libref, self.table, self._dsopts(), outstr, options); 65, identifier:code; 66, binary_operator:"by %s;" % by; 67, identifier:code; 68, string:"run\n;"; 69, identifier:runcode; 70, True; 71, attribute; 72, identifier:nosub; 73, expression_statement; 74, expression_statement; 75, identifier:ll; 76, call; 77, expression_statement; 78, expression_statement; 79, expression_statement; 80, for_statement; 81, if_statement; 82, if_statement; 83, block; 84, call; 85, block; 86, else_clause; 87, string_content:options; 88, assignment; 89, string:"proc sort data=%s.%s%s %s %s ;\n"; 90, tuple; 91, string:"by %s;"; 92, identifier:by; 93, identifier:self; 94, identifier:sas; 95, call; 96, assignment; 97, attribute; 98, argument_list; 99, assignment; 100, assignment; 101, assignment; 102, identifier:line; 103, call; 104, block; 105, call; 106, block; 107, not_operator; 108, block; 109, else_clause; 110, return_statement; 111, identifier:isinstance; 112, argument_list; 113, expression_statement; 114, if_statement; 115, block; 116, identifier:options; 117, subscript; 118, attribute; 119, attribute; 120, call; 121, identifier:outstr; 122, identifier:options; 123, identifier:print; 124, argument_list; 125, identifier:runcode; 126, False; 127, identifier:self; 128, identifier:_is_valid; 129, identifier:runcode; 130, False; 131, identifier:ll; 132, call; 133, identifier:elog; 134, list; 135, attribute; 136, argument_list; 137, if_statement; 138, identifier:len; 139, argument_list; 140, raise_statement; 141, call; 142, return_statement; 143, block; 144, identifier:self; 145, identifier:out; 146, identifier:str; 147, assignment; 148, comparison_operator:fn[1] == '.'; 149, block; 150, else_clause; 151, expression_statement; 152, expression_statement; 153, expression_statement; 154, identifier:kwargs; 155, string; 156, identifier:self; 157, identifier:libref; 158, identifier:self; 159, identifier:table; 160, attribute; 161, argument_list; 162, identifier:code; 163, attribute; 164, argument_list; 165, subscript; 166, identifier:splitlines; 167, call; 168, block; 169, identifier:elog; 170, call; 171, identifier:isinstance; 172, argument_list; 173, identifier:out; 174, return_statement; 175, identifier:fn; 176, call; 177, subscript; 178, string; 179, expression_statement; 180, expression_statement; 181, expression_statement; 182, block; 183, assignment; 184, assignment; 185, assignment; 186, string_content:options; 187, identifier:self; 188, identifier:_dsopts; 189, attribute; 190, identifier:submit; 191, identifier:code; 192, string:"text"; 193, identifier:ll; 194, string; 195, attribute; 196, argument_list; 197, expression_statement; 198, identifier:RuntimeError; 199, argument_list; 200, identifier:out; 201, identifier:str; 202, call; 203, attribute; 204, argument_list; 205, identifier:fn; 206, integer:1; 207, string_content:.; 208, assignment; 209, assignment; 210, assignment; 211, expression_statement; 212, expression_statement; 213, expression_statement; 214, identifier:libref; 215, attribute; 216, identifier:table; 217, attribute; 218, identifier:outstr; 219, binary_operator:"out=%s.%s" % (out.libref, out.table); 220, identifier:self; 221, identifier:sas; 222, string_content:LOG; 223, identifier:line; 224, identifier:startswith; 225, string; 226, call; 227, call; 228, attribute; 229, argument_list; 230, identifier:out; 231, identifier:partition; 232, string; 233, identifier:libref; 234, subscript; 235, identifier:table; 236, subscript; 237, identifier:outstr; 238, binary_operator:"out=%s.%s" % (libref, table); 239, assignment; 240, assignment; 241, assignment; 242, identifier:out; 243, identifier:libref; 244, identifier:out; 245, identifier:table; 246, string:"out=%s.%s"; 247, tuple; 248, string_content:ERROR; 249, attribute; 250, argument_list; 251, attribute; 252, argument_list; 253, attribute; 254, identifier:sasdata; 255, identifier:table; 256, identifier:libref; 257, attribute; 258, string_content:.; 259, identifier:fn; 260, integer:0; 261, identifier:fn; 262, integer:2; 263, string:"out=%s.%s"; 264, tuple; 265, identifier:libref; 266, string; 267, identifier:table; 268, subscript; 269, identifier:outstr; 270, binary_operator:"out=" + table; 271, attribute; 272, attribute; 273, identifier:elog; 274, identifier:append; 275, identifier:line; 276, string:"\n"; 277, identifier:join; 278, identifier:elog; 279, identifier:self; 280, identifier:sas; 281, identifier:self; 282, identifier:results; 283, identifier:libref; 284, identifier:table; 285, identifier:fn; 286, integer:0; 287, string:"out="; 288, identifier:table; 289, identifier:out; 290, identifier:libref; 291, identifier:out; 292, identifier:table
code: def sort(self, by: str, out: object = '', **kwargs) -> 'SASdata':
          """
          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'))
          """
          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.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