<?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: How to find the value in three consecutive ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666699#M199524</link>
    <description>&lt;P&gt;The output should look something like this&lt;/P&gt;&lt;P&gt;AGB 1 2 3&lt;/P&gt;&lt;P&gt;CONN 1 2 3&lt;/P&gt;&lt;P&gt;CAZ 1 2 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because these names appear in three consecutive ID's&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jul 2020 20:26:54 GMT</pubDate>
    <dc:creator>gbayya</dc:creator>
    <dc:date>2020-07-02T20:26:54Z</dc:date>
    <item>
      <title>How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666655#M199501</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the following table I'm trying to find the value in three consecutive ID's,&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample data&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Name&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AGB&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AGB&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CONN&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BGCA&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AGB&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CONN&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CAZ&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CONN&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CAZ&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AGB&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;JRSC&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABM&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABM&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BACO&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AGB&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; HFC&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BACO&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; HFC&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BACO&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; JKB&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HFC&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BACO&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; JKB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 17:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666655#M199501</guid>
      <dc:creator>gbayya</dc:creator>
      <dc:date>2020-07-02T17:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666662#M199505</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65239"&gt;@gbayya&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please explain the logic and show what the output would be? (a report / a dataset ?)&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 18:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666662#M199505</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-07-02T18:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666665#M199507</link>
      <description>&lt;P&gt;Is this what you're looking for?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=have_sorted; by name id; run;

data want (keep=name);
    set have_sorted;
    by name;
    retain count;
    if first.name then count = 1;
    else if count &amp;gt; 2 then; /* do nothing */
    else do;
        if lag(id) = id-1 then count + 1;
        else count = 1;
    end;
    if last.name and count &amp;gt;= 2 then output;
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jul 2020 18:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666665#M199507</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-07-02T18:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666699#M199524</link>
      <description>&lt;P&gt;The output should look something like this&lt;/P&gt;&lt;P&gt;AGB 1 2 3&lt;/P&gt;&lt;P&gt;CONN 1 2 3&lt;/P&gt;&lt;P&gt;CAZ 1 2 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because these names appear in three consecutive ID's&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 20:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666699#M199524</guid>
      <dc:creator>gbayya</dc:creator>
      <dc:date>2020-07-02T20:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666700#M199525</link>
      <description>&lt;P&gt;Thank you for the solution, but i am expecting something like the below output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should look something like this&lt;/P&gt;&lt;P&gt;AGB 1 2 3&lt;/P&gt;&lt;P&gt;CONN 1 2 3&lt;/P&gt;&lt;P&gt;CAZ 1 2 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;because these names appear in three consecutive ID's&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 20:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666700#M199525</guid>
      <dc:creator>gbayya</dc:creator>
      <dc:date>2020-07-02T20:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666701#M199526</link>
      <description>&lt;P&gt;Why is CAZ included? You only had that NAME twice in your original data. Perhaps you meant BACO, instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And are those numbers supposed to represent the IDs for the NAMEs that appear 3+ times? E.g.:&lt;/P&gt;
&lt;PRE&gt;Name      ID
AGB       1 2 3 4
BACO      4 5 6 7
CONN      1 2 3&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jul 2020 20:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666701#M199526</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-07-02T20:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666703#M199528</link>
      <description>&lt;P&gt;I presume you want to find any instances of a name appearing in 3 or more consecutive id's.&amp;nbsp; Let's say you want a dataset of the qualifying names with 3 variables:&amp;nbsp; name,start_id, end_id.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID  Name :$4.  @@;
datalines;
1 AGB     1 AGB    1 CONN
1 BGCA    2 AGB    2 CONN
2 CAZ     3 CONN    3 CAZ
3 AGB     3 JRSC    4 ABM
4 ABM     4 BACO    4 AGB
4 HFC     5 BACO    5 HFC
6 BACO    6 JKB     7 HFC
7 BACO    7 JKB
1 xxx   2 xxx 3 xxx    5 xxx 6 xxx 7 xxx 8 xxx
run;

proc sort data=have nodupkey  out=need;
  by name id;
run;

data want (rename=(id=end_id) drop=nxt_:);
  set need (keep=name);
  by name;
  merge need need (firstobs=2 keep=id rename=(id=nxt_id)) ;
  retain start_id ;
  if first.name=1 or lag(id)^=id-1 then start_id=id;
  if (last.name=1 or nxt_id&amp;gt;id+1) and start_id&amp;lt;=id-2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I added some records for name=xxx, to show what happens if a given name has 2 (or more) unconnected series satisfying your conditions.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;The "set need ... by name" statemetn pair is there to tell sas only to create 2 dummy variables (first.name and last.name) to tell when the record-in-hand is the start (or end) of a given id.&amp;nbsp; Note it only reads one variable.&amp;nbsp; That's becuase of the self-merge that follows.&lt;/LI&gt;
&lt;LI&gt;The self-merge retrieve all the data in the current record and one variabl (ID renamed to nxt_id) in the upcoming record.&amp;nbsp; This way you can tell if the next record will have the next id, or present an id "gap".&lt;/LI&gt;
&lt;LI&gt;Every time the data step starts a new id, or starts after a gap in the current it, then START_ID is reset.&lt;/LI&gt;
&lt;LI&gt;The second if is a "subsetting if" keeping only instances when you are at the end of an id or just before a gap within an id,&amp;nbsp; and you have processed 3 (or more) consecutive id's with the same name.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 02 Jul 2020 20:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666703#M199528</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-07-02T20:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the value in three consecutive ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666755#M199558</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for the solution, perfect.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 07:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-value-in-three-consecutive-ID/m-p/666755#M199558</guid>
      <dc:creator>gbayya</dc:creator>
      <dc:date>2020-07-03T07:46:57Z</dc:date>
    </item>
  </channel>
</rss>

