<?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: Reg :Continous obs in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16417#M3019</link>
    <description>Maybe you want pure data step code which is more readable:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data n;&lt;BR /&gt;
input aaccno id;&lt;BR /&gt;
count+1;&lt;BR /&gt;
cards;&lt;BR /&gt;
23 0&lt;BR /&gt;
23 1&lt;BR /&gt;
23 2&lt;BR /&gt;
23 3&lt;BR /&gt;
23 0&lt;BR /&gt;
24 1&lt;BR /&gt;
24 4&lt;BR /&gt;
24 2&lt;BR /&gt;
24 3&lt;BR /&gt;
26 1&lt;BR /&gt;
26 2&lt;BR /&gt;
26 3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data _n;&lt;BR /&gt;
 set n;&lt;BR /&gt;
 if id=3 and lag(id)=2 and lag2(id)=1 and &lt;BR /&gt;
     aaccno=lag(aaccno) and aaccno=lag2(aaccno) then output;&lt;BR /&gt;
run;&lt;BR /&gt;
data _n;&lt;BR /&gt;
 set _n;&lt;BR /&gt;
 output;&lt;BR /&gt;
 count=count-1;output;&lt;BR /&gt;
 count=count-1;output;&lt;BR /&gt;
 keep count;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=_n;&lt;BR /&gt;
 by count;&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
 merge n _n(in=in__n);&lt;BR /&gt;
 by count;&lt;BR /&gt;
 if in__n then flag=1;&lt;BR /&gt;
  else flag=0;&lt;BR /&gt;
 keep id flag;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Mon, 28 Feb 2011 03:37:46 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-02-28T03:37:46Z</dc:date>
    <item>
      <title>Reg :Continous obs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16412#M3014</link>
      <description>Hi i ma having a variable id if it is continously geeting 1 ,2,3 then flag should create as 1 based on accno&lt;BR /&gt;
&lt;BR /&gt;
dataset&lt;BR /&gt;
data n;&lt;BR /&gt;
input aaccno id;&lt;BR /&gt;
cards;&lt;BR /&gt;
23 0&lt;BR /&gt;
23 1&lt;BR /&gt;
23 2&lt;BR /&gt;
23 3&lt;BR /&gt;
23 0&lt;BR /&gt;
24 1&lt;BR /&gt;
24 4&lt;BR /&gt;
24 2&lt;BR /&gt;
24 3&lt;BR /&gt;
26 1&lt;BR /&gt;
26 2&lt;BR /&gt;
26 3&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
output:&lt;BR /&gt;
&lt;BR /&gt;
data n;&lt;BR /&gt;
input id flag;&lt;BR /&gt;
cards;&lt;BR /&gt;
0 0&lt;BR /&gt;
1 1&lt;BR /&gt;
2 1&lt;BR /&gt;
3  1&lt;BR /&gt;
0 0&lt;BR /&gt;
1 0&lt;BR /&gt;
4 0&lt;BR /&gt;
2 0&lt;BR /&gt;
3 0&lt;BR /&gt;
1 1&lt;BR /&gt;
2 1&lt;BR /&gt;
3 1&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 24 Feb 2011 07:04:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16412#M3014</guid>
      <dc:creator>R_Win</dc:creator>
      <dc:date>2011-02-24T07:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reg :Continous obs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16413#M3015</link>
      <description>hello,&lt;BR /&gt;
&lt;BR /&gt;
you can try merging data with itself without by statement:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data n;&lt;BR /&gt;
input aaccno id;&lt;BR /&gt;
cards;&lt;BR /&gt;
23 0&lt;BR /&gt;
23 1&lt;BR /&gt;
23 2&lt;BR /&gt;
23 3&lt;BR /&gt;
23 0&lt;BR /&gt;
24 1&lt;BR /&gt;
24 4&lt;BR /&gt;
24 2&lt;BR /&gt;
24 3&lt;BR /&gt;
26 1&lt;BR /&gt;
26 2&lt;BR /&gt;
26 3&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data x;&lt;BR /&gt;
merge n n(firstobs=2 rename=(id=id2 aaccno=aaccno2)) n(firstobs=3 rename=(id=id3 aaccno=aaccno3));&lt;BR /&gt;
&lt;BR /&gt;
retain flag;&lt;BR /&gt;
&lt;BR /&gt;
if aaccno=aaccno2=aaccno3 and id=1 and id2=2 and id3=3 then flag=1;&lt;BR /&gt;
if id not in (1,2,3) then flag=0;&lt;BR /&gt;
&lt;BR /&gt;
keep aaccno id flag;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Thu, 24 Feb 2011 09:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16413#M3015</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-24T09:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reg :Continous obs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16414#M3016</link>
      <description>OK.&lt;BR /&gt;
I think your task is tough,so force me to use hash table as a combination of arrarys .&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
data n;&lt;BR /&gt;
input aaccno id;&lt;BR /&gt;
&lt;B&gt;count+1;&lt;/B&gt;&lt;BR /&gt;
cards;&lt;BR /&gt;
23 0&lt;BR /&gt;
23 1&lt;BR /&gt;
23 2&lt;BR /&gt;
23 3&lt;BR /&gt;
23 0&lt;BR /&gt;
24 1&lt;BR /&gt;
24 4&lt;BR /&gt;
24 2&lt;BR /&gt;
24 3&lt;BR /&gt;
26 1&lt;BR /&gt;
26 2&lt;BR /&gt;
26 3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want(keep=aaccno id flag);&lt;BR /&gt;
 declare hash hh(hashexp: 10);&lt;BR /&gt;
 hh.definekey('count','aaccno','id');&lt;BR /&gt;
 hh.definedone();&lt;BR /&gt;
&lt;BR /&gt;
 do until(last);&lt;BR /&gt;
  set n end=last;&lt;BR /&gt;
  if id=3 and lag(id)=2 and lag2(id)=1 and &lt;BR /&gt;
     aaccno=lag(aaccno) and aaccno=lag2(aaccno) then do;&lt;BR /&gt;
                                                     hh.add();&lt;BR /&gt;
                                                     _count=count-1;&lt;BR /&gt;
                                                     set n point=_count;&lt;BR /&gt;
                                                     hh.add();&lt;BR /&gt;
                                                     _count=count-1;&lt;BR /&gt;
                                                     set n point=_count;&lt;BR /&gt;
                                                     hh.add();&lt;BR /&gt;
                                                     end;&lt;BR /&gt;
 end;&lt;BR /&gt;
&lt;BR /&gt;
 do until(_last);&lt;BR /&gt;
  set n end=_last;&lt;BR /&gt;
  rc=hh.check();&lt;BR /&gt;
  if rc eq 0 then flag=1;&lt;BR /&gt;
   else flag=0;&lt;BR /&gt;
  output;&lt;BR /&gt;
 end;&lt;BR /&gt;
 stop;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 24 Feb 2011 09:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16414#M3016</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-24T09:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Reg :Continous obs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16415#M3017</link>
      <description>THQS</description>
      <pubDate>Thu, 24 Feb 2011 10:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16415#M3017</guid>
      <dc:creator>R_Win</dc:creator>
      <dc:date>2011-02-24T10:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reg :Continous obs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16416#M3018</link>
      <description>Hi.&lt;BR /&gt;
Actually, My code can be refined as :&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data n;&lt;BR /&gt;
input aaccno id;&lt;BR /&gt;
&lt;B&gt;count+1;&lt;/B&gt;&lt;BR /&gt;
cards;&lt;BR /&gt;
23 0&lt;BR /&gt;
23 1&lt;BR /&gt;
23 2&lt;BR /&gt;
23 3&lt;BR /&gt;
23 0&lt;BR /&gt;
24 1&lt;BR /&gt;
24 4&lt;BR /&gt;
24 2&lt;BR /&gt;
24 3&lt;BR /&gt;
26 1&lt;BR /&gt;
26 2&lt;BR /&gt;
26 3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want(keep=aaccno id flag);&lt;BR /&gt;
 declare hash hh(hashexp: 10);&lt;BR /&gt;
 hh.definekey('count');&lt;BR /&gt;
 hh.definedone();&lt;BR /&gt;
&lt;BR /&gt;
 do until(last);&lt;BR /&gt;
  set n end=last;&lt;BR /&gt;
  if id=3 and lag(id)=2 and lag2(id)=1 and &lt;BR /&gt;
     aaccno=lag(aaccno) and aaccno=lag2(aaccno) then do;&lt;BR /&gt;
                                                     hh.add();&lt;BR /&gt;
                                                     count=count-1;&lt;BR /&gt;
                                                     hh.add();&lt;BR /&gt;
                                                     count=count-1;&lt;BR /&gt;
                                                     hh.add();&lt;BR /&gt;
                                                     end;&lt;BR /&gt;
 end;&lt;BR /&gt;
 &lt;BR /&gt;
 do until(_last);&lt;BR /&gt;
  set n end=_last;&lt;BR /&gt;
  rc=hh.check();&lt;BR /&gt;
  if rc eq 0 then flag=1;&lt;BR /&gt;
   else flag=0;&lt;BR /&gt;
  output;&lt;BR /&gt;
 end;&lt;BR /&gt;
 stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 25 Feb 2011 01:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16416#M3018</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-25T01:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Reg :Continous obs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16417#M3019</link>
      <description>Maybe you want pure data step code which is more readable:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data n;&lt;BR /&gt;
input aaccno id;&lt;BR /&gt;
count+1;&lt;BR /&gt;
cards;&lt;BR /&gt;
23 0&lt;BR /&gt;
23 1&lt;BR /&gt;
23 2&lt;BR /&gt;
23 3&lt;BR /&gt;
23 0&lt;BR /&gt;
24 1&lt;BR /&gt;
24 4&lt;BR /&gt;
24 2&lt;BR /&gt;
24 3&lt;BR /&gt;
26 1&lt;BR /&gt;
26 2&lt;BR /&gt;
26 3&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data _n;&lt;BR /&gt;
 set n;&lt;BR /&gt;
 if id=3 and lag(id)=2 and lag2(id)=1 and &lt;BR /&gt;
     aaccno=lag(aaccno) and aaccno=lag2(aaccno) then output;&lt;BR /&gt;
run;&lt;BR /&gt;
data _n;&lt;BR /&gt;
 set _n;&lt;BR /&gt;
 output;&lt;BR /&gt;
 count=count-1;output;&lt;BR /&gt;
 count=count-1;output;&lt;BR /&gt;
 keep count;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=_n;&lt;BR /&gt;
 by count;&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
 merge n _n(in=in__n);&lt;BR /&gt;
 by count;&lt;BR /&gt;
 if in__n then flag=1;&lt;BR /&gt;
  else flag=0;&lt;BR /&gt;
 keep id flag;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 28 Feb 2011 03:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16417#M3019</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-28T03:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reg :Continous obs</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16418#M3020</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I've looked upon my code and there where some situations which it does not cover.&lt;BR /&gt;
So I have added another if condition:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data x;&lt;BR /&gt;
merge n n(firstobs=2 rename=(id=id2 aaccno=aaccno2)) n(firstobs=3 rename=(id=id3 aaccno=aaccno3));&lt;BR /&gt;
&lt;BR /&gt;
retain flag ;&lt;BR /&gt;
&lt;BR /&gt;
if aaccno ne lag(aaccno) or id-lag(id) ne 1 then flag=0;*reset flag when first aaccno or id not continous;&lt;BR /&gt;
if aaccno=aaccno2=aaccno3 and id=1 and id2=2 and id3=3 then flag=1;&lt;BR /&gt;
if id not in (1,2,3) then flag=0;&lt;BR /&gt;
&lt;BR /&gt;
keep aaccno id flag;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Mon, 28 Feb 2011 09:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Reg-Continous-obs/m-p/16418#M3020</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-28T09:34:36Z</dc:date>
    </item>
  </channel>
</rss>

