<?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: Help in my pgm logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625795#M184502</link>
    <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id par $ ady;
datalines;
1 a 3
1 a 6
1 a 9
1 a 12
1 a 3
2 a 6
2 a 12
3 a 3
3 a 9
;

proc sort data=have nodupkey;
by id par ady;
run;

data want;
retain id par ady want; /* only for settting variable order */
want = 'Y';
do until (last.par);
  set have;
  by id par;
  if ady - prevady &amp;gt; 3 and not first.par then want = 'N';
  prevady = ady;
end;
do until (last.par);
  set have (rename=(ady=_ady));
  by id par;
  if not first.par then do ady = prevady + 3 to _ady by 3;
    output;
  end;
  else do ady = 3 to _ady by 3;
    output;
  end;
  prevady = _ady;
end;
drop prevady _ady;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;id	par	ady	want
1	a	3	Y
1	a	6	Y
1	a	9	Y
1	a	12	Y
2	a	3	N
2	a	6	N
2	a	9	N
2	a	12	N
3	a	3	N
3	a	6	N
3	a	9	N
&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Feb 2020 08:05:53 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-02-19T08:05:53Z</dc:date>
    <item>
      <title>Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625778#M184493</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id par $ ady;
datalines;
1 a 3
1 a 6
1 a 9
1 a 12
1 a 3
2 a 6
2 a 12
3 a 3
3 a 9
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Dear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help&amp;nbsp; to derive the logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if a subject has a record&amp;nbsp; in any 3 interval (3,6,9,12,15,18 ) then i need to create variable want='Yes' for the id and par and ady . If no record then want='No'. for the all the records until last record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&amp;nbsp; &amp;nbsp;id=1, has max ady is 12 and has all interval up to 12&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id=2&amp;nbsp; has&amp;nbsp; max&amp;nbsp; &amp;nbsp;ady 12&amp;nbsp; and has missed&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; so i create record with&amp;nbsp; &amp;nbsp;N&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id=3&amp;nbsp; &amp;nbsp;has&amp;nbsp; &amp;nbsp;max&amp;nbsp; ady&amp;nbsp; 9&amp;nbsp; and has missed&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp;so i create&amp;nbsp; &amp;nbsp; record with N&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; par&amp;nbsp; &amp;nbsp;ady&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;want&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&amp;nbsp; &amp;nbsp;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/FONT&gt;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/FONT&gt;&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;BR /&gt;&lt;BR /&gt;;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 04:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625778#M184493</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-02-19T04:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625785#M184496</link>
      <description>&lt;P&gt;data one;&lt;BR /&gt;input id par $ ady;&lt;BR /&gt;datalines;&lt;BR /&gt;1 a 3&lt;BR /&gt;1 a 6&lt;BR /&gt;1 a 9&lt;BR /&gt;1 a 12&lt;BR /&gt;1 a 3&lt;BR /&gt;2 a 6&lt;BR /&gt;2 a 12&lt;BR /&gt;3 a 3&lt;BR /&gt;3 a 9&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select b.id,b.par,b.ady,coalescec(b.want,'N') as want&lt;BR /&gt;from (select * from (select distinct id from one),(select distinct ady from one)) as a &lt;BR /&gt;right join &lt;BR /&gt;(select *,'Y' as want from one) as b on a.id=b.id and a.ady=b.ady;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 06:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625785#M184496</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-02-19T06:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625790#M184499</link>
      <description>&lt;P&gt;using a SAS data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id par $ ady;
  datalines;
1 a 3
1 a 6
1 a 9
1 a 12
2 a 3
2 a 6
2 a 12
3 a 3
3 a 9
;

data want(drop=_:);
  set have;
  by id ady;
  _start=sum(lag(ady),3);
  if first.id then _start=ady;
  _stop=ady;
  do ady=_start to _stop by 3;
    if ady = _stop then want='Y';
    else want='N';
    output;
  end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 07:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625790#M184499</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-19T07:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625795#M184502</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id par $ ady;
datalines;
1 a 3
1 a 6
1 a 9
1 a 12
1 a 3
2 a 6
2 a 12
3 a 3
3 a 9
;

proc sort data=have nodupkey;
by id par ady;
run;

data want;
retain id par ady want; /* only for settting variable order */
want = 'Y';
do until (last.par);
  set have;
  by id par;
  if ady - prevady &amp;gt; 3 and not first.par then want = 'N';
  prevady = ady;
end;
do until (last.par);
  set have (rename=(ady=_ady));
  by id par;
  if not first.par then do ady = prevady + 3 to _ady by 3;
    output;
  end;
  else do ady = 3 to _ady by 3;
    output;
  end;
  prevady = _ady;
end;
drop prevady _ady;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;id	par	ady	want
1	a	3	Y
1	a	6	Y
1	a	9	Y
1	a	12	Y
2	a	3	N
2	a	6	N
2	a	9	N
2	a	12	N
3	a	3	N
3	a	6	N
3	a	9	N
&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 08:05:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625795#M184502</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-19T08:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625826#M184517</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really like the SQL code.&amp;nbsp; But it is not giving me the output i need.&amp;nbsp; Please suggest. I got help from other people in&amp;nbsp; group. But i interested to know SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 12:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625826#M184517</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-02-19T12:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625851#M184525</link>
      <description>&lt;P&gt;Every time you need to build (or work with) sequences, the data step is the tool of choice. SQL is not really good at this, unless you work with a flavor that has non-ANSI extensions.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 14:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625851#M184525</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-19T14:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625874#M184534</link>
      <description>&lt;P&gt;HI Thank you very much for the help.&amp;nbsp; &amp;nbsp;I am adding my input dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think some modification is needed in your suggestion. It is not giving me correct output.&amp;nbsp; I need to populate want=N only if there is no record. (missing ).&amp;nbsp; &amp;nbsp; &amp;nbsp;F&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id par $ ady;
datalines;
1 a 3
1 a 6
1 a 9
1 a 12
2 a 6
2 a 12
3 a 3
3 a 9
;
proc sort data=one;
by id ady;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or subjects 2 and 3&amp;nbsp; i am having all&amp;nbsp; &amp;nbsp;N.&amp;nbsp; &amp;nbsp;Please help. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output needed&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; par&amp;nbsp; &amp;nbsp;ady&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;want&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#FF6600"&gt;&amp;nbsp;N&lt;/FONT&gt;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/FONT&gt;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/FONT&gt;&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output getting&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; par&amp;nbsp; &amp;nbsp;ady&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;want&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&amp;nbsp; &amp;nbsp;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/FONT&gt;&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/FONT&gt;&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 15:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625874#M184534</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2020-02-19T15:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625899#M184543</link>
      <description>&lt;P&gt;To me this looks like you want fill out a planned set of records.&lt;/P&gt;
&lt;P&gt;It is not clear where you are getting the set of possible ADY values.&amp;nbsp; Is it just from the values that already appear in ONE?&lt;/P&gt;
&lt;P&gt;If so then this type of query pattern will let you get all possible combinations of ID+PAR and ADY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select *,'N' as EXTRA 
from (select distinct id,par from one)
   , (select distinct ady from one)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not then you need to first make a little dataset that have one observation per value of ADY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ady_list;
 do ady=3 to 12 by 3;
    output;
  end;
run;
proc sql
select *,'N' as EXTRA 
from (select distinct id,par from one)
   , ady_list
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Either way now that you have the full skeleton merge it with the actual data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want(drop=actual extra) as
select *
     , coalesce(ACTUAL,EXTRA) as WANT
from (select *,'Y' as ACTUAL from one) a
natural full join 
(
select *,'N' as EXTRA 
from (select distinct id,par from one)
   , (select distinct ady from one)
) b
;
quit;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id    par    ady    WANT

  1     1     a       3     Y
  2     1     a       6     Y
  3     1     a       9     Y
  4     1     a      12     Y
  5     2     a       3     N
  6     2     a       6     Y
  7     2     a       9     N
  8     2     a      12     Y
  9     3     a       3     Y
 10     3     a       6     N
 11     3     a       9     Y
 12     3     a      12     N
&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 17:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625899#M184543</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-19T17:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625957#M184559</link>
      <description>&lt;P&gt;This is a case where you compare the record-in-hand to the prior record.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are any gaps (comparing _PRIOR_ADY to current ADY-3), loop through the gap (incrementing ADY by 3's from the prior_ady), outputting "extra" records with WANT='N'.&amp;nbsp; The loop will end up with ADY equal the current actual value.&amp;nbsp; So set want='Y' and output the actual record:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id par $ ady;
datalines;
1 a 3
1 a 6
1 a 9
1 a 12
2 a 6
2 a 12
3 a 3
3 a 9
;
data want;
  set one ;
  by id;
  _prior_ady=ifn(first.id,0,lag(ady));
  if _prior_ady^=ady-3 then do ady=_prior_ady +3 to ady-3 by 3;
    want='N';
    output;
  end;
  want='Y';
  output;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But my comments above didn't say what to do about starting and ID with, say ADY=6.&amp;nbsp; This is solved by setting the _PRIOR_ADY value to 0 when at the beginning of an ID.&amp;nbsp; Only if the ID starts with ADY=3 there is no gap.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 19:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/625957#M184559</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-19T19:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help in my pgm logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/626057#M184591</link>
      <description>&lt;P&gt;That makes the logic simpler, as we don't need the double do until loop, instead doing everything with counting iterations:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id par $ ady;
datalines;
1 a 3
1 a 6
1 a 9
1 a 12
1 a 3
2 a 6
2 a 12
3 a 3
3 a 9
;

proc sort data=have nodupkey;
by id par ady;
run;

data want;
set have (rename=(ady=_ady));
by id par;
_prev = lag(_ady);
if first.par
then do ady = 3 to _ady - 3 by 3; /* fill from the start */
  want = 'N';
  output;
end;
else do ady = _prev + 3 to _ady - 3 by 3; /* fill a hole */
  want = 'N';
  output;
end;
/* write the current obs */
want = 'Y';
ady = _ady;
output;
drop _:;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;id    par    ady    want

 1     a       3     Y  
 1     a       6     Y  
 1     a       9     Y  
 1     a      12     Y  
 2     a       3     N  
 2     a       6     Y  
 2     a       9     N  
 2     a      12     Y  
 3     a       3     Y  
 3     a       6     N  
 3     a       9     Y  
&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2020 06:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-my-pgm-logic/m-p/626057#M184591</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-20T06:31:24Z</dc:date>
    </item>
  </channel>
</rss>

