<?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: checking for sequential order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490926#M128610</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Sample_ID $;
c=compress(Sample_ID,,'ka');
n=input(compress(Sample_ID,,'kd'),8.);
cards;
A-001
A-002
A-003
A-004
A-010
A-011
A-012
B-001
B-002
B-004
;
data want;
set have;
by c;
k=dif(n);
if not first.c and k ne 1 then Out_of_order='YES';
keep sample_id Out_of_order;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Aug 2018 17:27:12 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-08-29T17:27:12Z</dc:date>
    <item>
      <title>checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490913#M128602</link>
      <description>&lt;P&gt;I have a large data set, and one of the sorted column is like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample_ID&lt;/P&gt;&lt;P&gt;A-001&lt;/P&gt;&lt;P&gt;A-002&lt;/P&gt;&lt;P&gt;A-003&lt;/P&gt;&lt;P&gt;A-004&lt;/P&gt;&lt;P&gt;A-010&lt;/P&gt;&lt;P&gt;A-011&lt;/P&gt;&lt;P&gt;A-012&lt;/P&gt;&lt;P&gt;B-001&lt;/P&gt;&lt;P&gt;B-002&lt;/P&gt;&lt;P&gt;and so on...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to add a new column to identify the samples that out of sequential order (discontinue&amp;nbsp; ID numbers), the new column I want is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample_ID&amp;nbsp; &amp;nbsp; &amp;nbsp; Out_of_order&lt;/P&gt;&lt;P&gt;A-001&lt;/P&gt;&lt;P&gt;A-002&lt;/P&gt;&lt;P&gt;A-003&lt;/P&gt;&lt;P&gt;A-004&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;A-010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;/P&gt;&lt;P&gt;A-011&lt;/P&gt;&lt;P&gt;A-012&lt;/P&gt;&lt;P&gt;B-001&lt;/P&gt;&lt;P&gt;B-002&lt;/P&gt;&lt;P&gt;B-004&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;/P&gt;&lt;P&gt;and so on...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know if there are any way to approach it or similar result, thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 16:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490913#M128602</guid>
      <dc:creator>y_fu</dc:creator>
      <dc:date>2018-08-29T16:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490916#M128604</link>
      <description>&lt;P&gt;in a data step, you can use the lag function to look at previous rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;A name="a003122427" target="_blank"&gt;&lt;/A&gt;options pagesize= linesize= pageno=1 nodate;

data one;
   input x @@;
   y=lag1(x);
   z=lag2(x);
   datalines;
1 2 3 4 5 6
;

proc print data=one;
   title 'LAG Output';
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="titleRefaid"&gt;&lt;A name="a003122429" target="_blank"&gt;&lt;/A&gt;Output from Generating Two Lagged Values&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;                                  LAG Output                                 1

                              Obs    x    y    z

                               1     1    .    .
                               2     2    1    .
                               3     3    2    1
                               4     4    3    2
                               5     5    4    3
                               6     6    5    4
&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490916#M128604</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2018-08-29T17:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490918#M128606</link>
      <description>&lt;P&gt;I have a large data set that has more than 1000 obs. I do not think lag function will be efficient.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490918#M128606</guid>
      <dc:creator>y_fu</dc:creator>
      <dc:date>2018-08-29T17:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490922#M128607</link>
      <description>&lt;P&gt;Why is Out_Of_Order not equal to 'Yes' for&amp;nbsp;&lt;SPAN&gt;B-001?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490922#M128607</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-08-29T17:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490923#M128608</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222061"&gt;@y_fu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a large data set that has more than 1000 obs. I do not think lag function will be efficient.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the values are sorted then you only need to look at the previous record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input sample_id $;
datalines;
A-001
A-002
A-003
A-004
A-010 
A-011
A-012
B-001
B-002
B-004
;
run;

data want;
   set have;
   prefix=scan(sample_id,1,'-');
   lprefix=scan(lag(sample_id),1,'-');
   order = input(scan(sample_id,2,'-'),4.);
   lorder = input(scan(lag(sample_id),2,'-'),4.);
   Outoforder = (prefix=lprefix) and (order ne (lorder+1));
   drop prefix lprefix order lorder;
run;
&lt;/PRE&gt;
&lt;P&gt;You do not specify if the A, B etc value has to be checked in any way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also do not specify if the first A, B etc value has to be 001 or not.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490923#M128608</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-29T17:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490926#M128610</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Sample_ID $;
c=compress(Sample_ID,,'ka');
n=input(compress(Sample_ID,,'kd'),8.);
cards;
A-001
A-002
A-003
A-004
A-010
A-011
A-012
B-001
B-002
B-004
;
data want;
set have;
by c;
k=dif(n);
if not first.c and k ne 1 then Out_of_order='YES';
keep sample_id Out_of_order;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490926#M128610</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-29T17:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490927#M128611</link>
      <description>&lt;P&gt;Sorry, I should be more specific.&lt;/P&gt;&lt;P&gt;The A,B,C etc. check will not be necessary, and all of the group of samples will start with -001&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490927#M128611</guid>
      <dc:creator>y_fu</dc:creator>
      <dc:date>2018-08-29T17:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: checking for sequential order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490928#M128612</link>
      <description>&lt;P&gt;Thank you for the help! It is the result I want.&lt;/P&gt;&lt;P&gt;It is nice to learn something new about how to use compress function.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/checking-for-sequential-order/m-p/490928#M128612</guid>
      <dc:creator>y_fu</dc:creator>
      <dc:date>2018-08-29T17:33:01Z</dc:date>
    </item>
  </channel>
</rss>

