<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Find presorted variables from unknow sas dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868779#M343208</link>
    <description>You mean "Alphabetic List of Variables and Attributes" in this section the number indicates sorting order of the dataset?</description>
    <pubDate>Sun, 09 Apr 2023 15:05:32 GMT</pubDate>
    <dc:creator>chinna0369</dc:creator>
    <dc:date>2023-04-09T15:05:32Z</dc:date>
    <item>
      <title>Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868775#M343204</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to find the variable list of a sorted dataset?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Adithya&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 14:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868775#M343204</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2023-04-09T14:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868776#M343205</link>
      <description>I mean by which variables the dataset is sorted by?</description>
      <pubDate>Sun, 09 Apr 2023 15:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868776#M343205</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2023-04-09T15:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868778#M343207</link>
      <description>&lt;P&gt;PROC CONTENTS will do this.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 15:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868778#M343207</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-09T15:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868779#M343208</link>
      <description>You mean "Alphabetic List of Variables and Attributes" in this section the number indicates sorting order of the dataset?</description>
      <pubDate>Sun, 09 Apr 2023 15:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868779#M343208</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2023-04-09T15:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868780#M343209</link>
      <description>&lt;P&gt;No that's not what I mean. The list of variables by which the data set is sorted is in a different section of the output. See &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1a5k5u51pvnlhn17j9v82nciokh.htm#n1a5k5u51pvnlhn17j9v82nciokh" target="_self"&gt;this example&lt;/A&gt;, scroll all the way down to the bottom.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 15:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868780#M343209</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-09T15:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868784#M343212</link>
      <description>No, I think it displays only when Sorted section says "YES" in "The Contents Procedure" section. But In my case it says "NO".</description>
      <pubDate>Sun, 09 Apr 2023 16:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868784#M343212</guid>
      <dc:creator>chinna0369</dc:creator>
      <dc:date>2023-04-09T16:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868787#M343213</link>
      <description>&lt;P&gt;So the data set was not sorted by SAS. It may have been created in a sorted order before it got into SAS (such as in Excel), in which case SAS does not know the sort variables.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 16:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868787#M343213</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-09T16:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868805#M343223</link>
      <description>&lt;P&gt;Here is one way to find potential candidates for the top level sorting.&lt;/P&gt;
&lt;P&gt;I leave it as an exercise how to generate this code for some arbitrary dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class end=eof;
  array incr [5] _temporary_ (5*1);
  array decr [5] _temporary_ (5*1);
  array names [5] $32 ('Name' 'Sex' 'Age' 'Height' 'Weight');
  if _N_&amp;gt;1 and lag(name)&amp;gt;name then incr[1]=0;
  if _N_&amp;gt;1 and lag(sex)&amp;gt;sex then incr[2]=0;
  if _N_&amp;gt;1 and lag(age)&amp;gt;age then incr[3]=0;
  if _N_&amp;gt;1 and lag(weight)&amp;gt;weight then incr[4]=0;
  if _N_&amp;gt;1 and lag(height)&amp;gt;height then incr[5]=0;
  if _N_&amp;gt;1 and lag(name)&amp;lt;name then decr[1]=0;
  if _N_&amp;gt;1 and lag(sex)&amp;lt;sex then decr[2]=0;
  if _N_&amp;gt;1 and lag(age)&amp;lt;age then decr[3]=0;
  if _N_&amp;gt;1 and lag(weight)&amp;lt;weight then decr[4]=0;
  if _N_&amp;gt;1 and lag(height)&amp;lt;height then decr[5]=0;
  
  if 0=max(of incr[*] decr[*]) then do;
    put 'NOTE: No sorting variables found.';
    stop;
  end;

  if eof then do i=1 to 5;
    if incr[i] then put 'NOTE: Sorting variable ' names[i] ;
    if decr[i] then put 'NOTE: Descending sorting variable ' names[i] ;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Apr 2023 21:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868805#M343223</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-09T21:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868811#M343224</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117414"&gt;@chinna0369&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No, I think it displays only when Sorted section says "YES" in "The Contents Procedure" section. But In my case it says "NO".&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just how many variables are involved? Just one data set or will you have to do this repeatedly? Or should all of these sets, if multiple, be sorted the same?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or look at the variables and sort in a way that makes sense for the following processing and don't worry about current order.&lt;/P&gt;
&lt;P&gt;You may well spend more time trying to solve this, at least to me, extremely minor issue than it is worth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 22:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868811#M343224</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-09T22:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868834#M343236</link>
      <description>&lt;P&gt;If you are going to do this once or twice, the "eyeball method" — look at the data set with your own eyes — will do this. If you have to do this repeatedly, then there is no easy method.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 09:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868834#M343236</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-10T09:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find presorted variables from unknow sas dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868846#M343241</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117414"&gt;@chinna0369&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. Not worth the effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no way to determine the sort order from a data set that ihas not previously been sorted by SAS, so always us a Proc Sort in cases where sorting is required. If a data set has previously been sorted by SAS, the procdure is smart enough&amp;nbsp;to omit sorting when data are already sorted in the wanted sequence, so It comes with no cost besides coding a couple of lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is mandatory in good coding practice to make sure that a data set is sorted before any use that requires sorting, which means all Data Steps with first-last variables, retain, lag or merge, and most SAS Procedures, except Proc SQL.&amp;nbsp;Always use a Proc Sort before these steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reverse applies to the order of variables. Don't put any effort in bringing variables in a specific order while preparing data. Leave that until you come to creating reports or exporting data to Excel.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2023 11:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-presorted-variables-from-unknow-sas-dataset/m-p/868846#M343241</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-04-10T11:37:21Z</dc:date>
    </item>
  </channel>
</rss>

