<?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: Fill rows with sequential data in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888415#M43422</link>
    <description>&lt;P&gt;If would be easier if you reversed the order because it is easier to REMEMBER something than PREDICT the future.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original_data;
    input var1 $ var2;
datalines;
A 12
B 15
C 20
D 23
;

proc sort data=original_data out=want;
  by descending var2;
run;

data want;
  set want;
  by descending var2;
  do var2=var2 to max(var2,lag(var2)-1);
    output;
  end;
run;

proc sort data=want;
  by var2;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The LAG() function let's you remember the value it was last passed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking into the future is harder.&amp;nbsp; Here is one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set original_data;
  set original_data(keep=var2 rename=(var2=next_var2) firstobs=2) original_data(drop=_all_ obs=1);
  do var2=var2 to max(var2,next_var2-1);
    output;
  end;
  drop next_var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2023 15:36:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-08-08T15:36:18Z</dc:date>
    <item>
      <title>Fill rows with sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888412#M43421</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS, I would like to obtain a SAS dataset that completes intermediate lines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data original_data;
    input var1 $ var2;
    datalines;
A 12
B 15
C 20
D 23
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to obtain another dataset with the intermediate lines like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data original_data;
    input var1 $ var2;
    datalines;
A 12
A 13
A 14
B 15
B 16
B 17
B 18
B 19
C 20
C 21
C 22
D 23
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 15:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888412#M43421</guid>
      <dc:creator>MM88</dc:creator>
      <dc:date>2023-08-08T15:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Fill rows with sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888415#M43422</link>
      <description>&lt;P&gt;If would be easier if you reversed the order because it is easier to REMEMBER something than PREDICT the future.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original_data;
    input var1 $ var2;
datalines;
A 12
B 15
C 20
D 23
;

proc sort data=original_data out=want;
  by descending var2;
run;

data want;
  set want;
  by descending var2;
  do var2=var2 to max(var2,lag(var2)-1);
    output;
  end;
run;

proc sort data=want;
  by var2;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The LAG() function let's you remember the value it was last passed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking into the future is harder.&amp;nbsp; Here is one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set original_data;
  set original_data(keep=var2 rename=(var2=next_var2) firstobs=2) original_data(drop=_all_ obs=1);
  do var2=var2 to max(var2,next_var2-1);
    output;
  end;
  drop next_var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 15:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888415#M43422</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-08T15:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fill rows with sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888416#M43423</link>
      <description>Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;. It works good. I appreciate your help.</description>
      <pubDate>Tue, 08 Aug 2023 15:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888416#M43423</guid>
      <dc:creator>MM88</dc:creator>
      <dc:date>2023-08-08T15:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Fill rows with sequential data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888419#M43424</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original_data;
    input var1 $ var2;
    datalines;
A 12
B 15
C 20
D 23
;
run;

data have;
 merge original_data 
       original_data(firstobs=2 
                     rename=(var1=var1accent var2=var2accent));
run;

data want(drop=var1accent var2: rename=(i=var2));
 set have end=last;
 if var2accent NE . then do;
   do i=var2 to (var2accent-1);
    output;
   end;
 end;
 if last then do; i=var2; output; end;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;DIV id="ConnectiveDocSignExtentionInstalled" data-extension-version="1.0.4"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 08 Aug 2023 15:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Fill-rows-with-sequential-data/m-p/888419#M43424</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-08-08T15:55:11Z</dc:date>
    </item>
  </channel>
</rss>

