<?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 How to check if data set is sorted in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942526#M369577</link>
    <description>&lt;P&gt;Let's say that I have a big data set and I want to know if this data set is sorted by variable CustID.&lt;/P&gt;
&lt;P&gt;What is the way to check it?&lt;/P&gt;
&lt;P&gt;I know that I can look at subset of few rows and see if it is sorted but it is still not perfect way because it might happen that in the next rows data set is not sorted&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2024 17:02:36 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2024-09-04T17:02:36Z</dc:date>
    <item>
      <title>How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942526#M369577</link>
      <description>&lt;P&gt;Let's say that I have a big data set and I want to know if this data set is sorted by variable CustID.&lt;/P&gt;
&lt;P&gt;What is the way to check it?&lt;/P&gt;
&lt;P&gt;I know that I can look at subset of few rows and see if it is sorted but it is still not perfect way because it might happen that in the next rows data set is not sorted&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 17:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942526#M369577</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T17:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942528#M369579</link>
      <description>You can run proc contents and check the SORTED output or use the SORT* variables in sashelp.vtable for a more dynamic approach if you want to check via code.</description>
      <pubDate>Wed, 04 Sep 2024 17:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942528#M369579</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-09-04T17:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942531#M369581</link>
      <description>&lt;P&gt;I run proc&amp;nbsp; &amp;nbsp;contents and it is written&amp;nbsp; sorted No&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents  data=csp.twoyrs_3;Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1725470354898.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99954iF2229ECEDBEABC0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1725470354898.png" alt="Ronein_0-1725470354898.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Howver I run code using by statemernt and didnt get any error so probably it is sorted!&lt;/P&gt;
&lt;P&gt;How can I find that it is sorted???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that I run this code and no have any error&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
pop7=0;
failure=0;
do until(last.LAKOACH);
set csp.twoyrs_3 end=eof;
by LAKOACH;
if (VALID_FROM_DTTM='01NOV2022'd and pop_lomeforat_wppr=7) then POP7=1;
if VALID_FROM_DTTM in ('01OCT2022'd,'01SEP2022'd ,'01AUG2022'd,'01JUL2022'd,'01JUN2022'd) and ind_shlili_6=1 then FAILURE=1;
end;
totalN+1;  /***Total rows checked----2,493,500****/
totalpop7 + POP7;  /****Base pop that is determined by belonging to pop 7 in month Nov 2022---108,552***/
totalpop7failure + (pop7 and failure);/***10,623***/
keep total: ;
if eof;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2024 17:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942531#M369581</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T17:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942536#M369583</link>
      <description>&lt;P&gt;Do you mean whether the data set is &lt;STRONG&gt;sorted&lt;/STRONG&gt;, meaning having been sorted previously by Proc Sort or Proc SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you mean whether the data set is in a particular &lt;STRONG&gt;order&lt;/STRONG&gt;, regardless of having been sorted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, this data set is ordered by ID. But is has not been sorted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID x;
datalines;
1 10 
2 20 
3 30 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a consequence, running Proc Contents against the data like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data = have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;will tell you that the data is not sorted. Because it has not been sorted (nor validated) by SAS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PeterClemmensen_0-1725470650200.png" style="width: 520px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99955i1CEF3054EDA261CB/image-dimensions/520x129?v=v2" width="520" height="129" role="button" title="PeterClemmensen_0-1725470650200.png" alt="PeterClemmensen_0-1725470650200.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If what you are after is a &lt;EM&gt;check&amp;nbsp;&lt;/EM&gt;of whether the data is in some particular order, then the &lt;STRONG&gt;Presorted Option&lt;/STRONG&gt;&amp;nbsp;on the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p02bhn81rn4u64n1b6l00ftdnxge.htm#p1vkld5nbc46lgn166zqz7k87aka" target="_self"&gt;Proc Sort Statement&lt;/A&gt; is the way to go.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 17:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942536#M369583</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-09-04T17:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942563#M369597</link>
      <description>Good question. &lt;BR /&gt;When I say sorted I mean that values are sorted by values by ascending order. It doesn't mean that proc sort or sort via proc sql was done before. Maybe values are built in sorted without any further code thst done to sort it. My question was how to check if values in Data set are sorted ? Yes/no</description>
      <pubDate>Wed, 04 Sep 2024 19:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942563#M369597</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T19:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942581#M369600</link>
      <description>&lt;P&gt;AFAIK, there isn't a way to know this without scanning the whole data set. So if a sort is important or required you need to sort the data so that there is an explicit sort indicator created on the dataset or so that you can trust it. If the data is already sorted, the sort procedure will be efficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 19:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942581#M369600</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-09-04T19:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942583#M369602</link>
      <description>&lt;P&gt;You can let SAS generate an error for you.&lt;/P&gt;
&lt;P&gt;Examples:&lt;/P&gt;
&lt;PRE&gt;275  %let sorted=NO;
276  data _null_;
277    if eof then call symputx('sorted','YES');
278    set sashelp.class end=eof;
279    by age;
280  run;

ERROR: BY variables are not properly sorted on data set SASHELP.CLASS.
eof=0 Name=Alfred Sex=M Age=14 Height=69 Weight=112.5 FIRST.Age=1 LAST.Age=1 _ERROR_=1 _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 2 observations read from the data set SASHELP.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


281  %put &amp;amp;=sorted;
SORTED=NO
282  %let sorted=NO;
283  data _null_;
284    if eof then call symputx('sorted','YES');
285    set sashelp.class end=eof;
286    by name;
287  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


288  %put &amp;amp;=sorted;
SORTED=YES
&lt;/PRE&gt;
&lt;P&gt;Or if you want to test yourself then use LAG() function and avoid the ERROR in the LOG.&lt;/P&gt;
&lt;PRE&gt;317  %let sorted=NO;
318  data _null_;
319    if eof then call symputx('sorted','YES');
320    set sashelp.class end=eof;
321    if age &amp;lt; lag(age) then stop;
322  run;

NOTE: There were 3 observations read from the data set SASHELP.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


323  %put &amp;amp;=sorted;
SORTED=NO
324  %let sorted=NO;
325  data _null_;
326    if eof then call symputx('sorted','YES');
327    set sashelp.class end=eof;
328    if name &amp;lt; lag(name) then stop;
329  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


330  %put &amp;amp;=sorted;
SORTED=YES
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 19:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942583#M369602</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-04T19:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942587#M369604</link>
      <description>From an efficiency standpoint, which is faster - sorting ahead of time or checking with the data step. My intuition says sort since the procedures are optimized while a data step has to run through all records (unless the out of order data is early in the dataset)</description>
      <pubDate>Wed, 04 Sep 2024 19:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942587#M369604</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-09-04T19:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942597#M369607</link>
      <description>&lt;P&gt;Depends on the goal.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The best sort procedures take O(NlogN) time and need at a minimum space to write two copies of the data (and for larger datasets even more for spill files).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading the dataset takes just O(N).&amp;nbsp; Plus since it does not need to write any data it should run even faster.&amp;nbsp; And when the data is not sorted it should on average fail before reading half of the data. But if the goal is to actually sort the data then all of that is wasted time except when it is already sorted.&amp;nbsp; So if you expect the data to be sorted a large percent of the time and just want detect then perhaps it is worth doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note also that PROC SORT should automatically detect when the dataset's metadata indicates it is sorted and not actually do anything in that case.&amp;nbsp; So PROC SORT should also benefit when the data is sorted (and SAS knows it is).&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 20:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942597#M369607</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-04T20:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942599#M369609</link>
      <description>&lt;P&gt;Here is an example of LOG running Sort on a data set already sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;62   proc sort data=sashelp.class;
63      by name;
64   run;

NOTE: Input data set is already sorted, no sorting done.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;Note that if the set had been sorted by a different variable(s) then it would sort it.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 20:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942599#M369609</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-09-04T20:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942605#M369613</link>
      <description>Thanks. You wrote -The best sort procedures take O(NlogN) time.&lt;BR /&gt;Can you show code ?&lt;BR /&gt;I know just the regular proc sort procedure but working on 100 million rows might be long time?</description>
      <pubDate>Wed, 04 Sep 2024 21:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942605#M369613</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T21:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942607#M369614</link>
      <description>You kean that If the data set is already sorted then proc sort procedure will not be done again so it is efficient?</description>
      <pubDate>Wed, 04 Sep 2024 21:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942607#M369614</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-09-04T21:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942617#M369620</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks. You wrote -The best sort procedures take O(NlogN) time.&lt;BR /&gt;Can you show code ?&lt;BR /&gt;I know just the regular proc sort procedure but working on 100 million rows might be long time?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Huh?&amp;nbsp; PROC SORT is the code to use to sort a dataset.&amp;nbsp; It has already been optimized by SAS.&amp;nbsp; There are option you can use too optimize it if you know something about the data.&amp;nbsp; For example if you have lot of variables (or really long character variables) and just a few short BY variables then using TAGSORT option might improve performance by not having to copy all of that data as many times.&amp;nbsp; But if you only have a few variables then TAGSORT will probably actually take longer since it will have to do more work.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 23:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942617#M369620</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-09-04T23:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942646#M369632</link>
      <description>&lt;P&gt;You have already had quite a lot of advice. However, there is one other reason checking with a data step may be the faster way - say we have a lot of variables, but only want to check sorting on a few of them, then you can use KEEP= to minimize the data that is actually read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May save quite a lot of memory, and possibly also some time, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sorted=NO;
data _null_;
  do until(eof);
    set sashelp.class(keep=age) end=eof;
    by age;
    end;
  call symputx('SORTED','YES');
run;

%put &amp;amp;=sorted;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put the DO UNTIL in because it saves the code to reset the variables to missing before reading each observation.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2024 07:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/942646#M369632</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2024-09-05T07:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943322#M369760</link>
      <description>I know.  If you need to sort after you check if the data is sorted and the answer is no, then you may as well sort in the first place.</description>
      <pubDate>Tue, 10 Sep 2024 15:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943322#M369760</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-09-10T15:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943418#M369766</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;Ideally you know your data and don't need such a check.&lt;/P&gt;
&lt;P&gt;As already mentioned by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;early on Proc Sort has a presorted option that makes the Proc first check if data is already sorted.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  set sashelp.class;
run;

proc sort data=have presorted;
  by name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1726008277278.png" style="width: 603px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100203i50867B2693475F90/image-dimensions/603x192?v=v2" width="603" height="192" role="button" title="Patrick_0-1726008277278.png" alt="Patrick_0-1726008277278.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Sep 2024 22:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943418#M369766</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-09-10T22:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943434#M369767</link>
      <description>You could create an index on this variable CustID . Like:&lt;BR /&gt;proc sql;&lt;BR /&gt;create index CustID on have;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;Once this index created , that means the table has been sorted by CustID, no need PROC SORT any more.</description>
      <pubDate>Wed, 11 Sep 2024 02:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943434#M369767</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-09-11T02:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943467#M369774</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using &lt;CODE&gt;PROC DATASETS&lt;/CODE&gt; to check the &lt;CODE&gt;SORTEDBY&lt;/CODE&gt; attribute:&lt;/P&gt;&lt;P&gt;SAS stores metadata on whether a dataset has been sorted using the &lt;CODE&gt;SORTEDBY&lt;/CODE&gt; attribute. You can check this metadata with &lt;CODE&gt;PROC DATASETS&lt;/CODE&gt;.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 177px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/100213i3CAD577E688CA432/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN class=""&gt;Copy code&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;In the output, if the &lt;CODE&gt;sortedby&lt;/CODE&gt; variable has a value, it indicates that the dataset is sorted by the corresponding variables. If the dataset is not sorted, the &lt;CODE&gt;sortedby&lt;/CODE&gt; variable will be blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2024 12:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943467#M369774</guid>
      <dc:creator>Sarath_A_SAS</dc:creator>
      <dc:date>2024-09-11T12:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943470#M369776</link>
      <description>&lt;A href="https://studysas.blogspot.com/2024/09/unleashing-power-of-proc-datasets-in.html" target="_blank"&gt;https://studysas.blogspot.com/2024/09/unleashing-power-of-proc-datasets-in.html&lt;/A&gt;</description>
      <pubDate>Wed, 11 Sep 2024 12:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943470#M369776</guid>
      <dc:creator>Sarath_A_SAS</dc:creator>
      <dc:date>2024-09-11T12:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if data set is sorted</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943561#M369799</link>
      <description>This is essentially the same answer as PROC SORT, which doesn't answer the problem (later defined in the thread), how to detect a data set that is in order but hasn't been explicitly sorted to have the sort flag in place. Otherwise, this is definitely a correct solution.</description>
      <pubDate>Wed, 11 Sep 2024 19:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-data-set-is-sorted/m-p/943561#M369799</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-09-11T19:30:08Z</dc:date>
    </item>
  </channel>
</rss>

