<?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 Add extra year rows in panel data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638507#M189872</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset like below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input firmID $	Year	Value;
datalines;
A	1995	1
A	1996	1
A	1997	1
A	1998	1
B	1997	2
B	1998	2
B	1999	2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to add one more year for each firm while keeping the value the same. The expected output is below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input firmID $	Year	Value;
datalines;
A	1995	1
A	1996	1
A	1997	1
A	1998	1
&lt;FONT color="#FF0000"&gt;A   1999    1&lt;/FONT&gt;
B	1997	2
B	1998	2
B	1999	2
&lt;FONT color="#FF0000"&gt;B   2000    2&lt;/FONT&gt;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2020 21:45:09 GMT</pubDate>
    <dc:creator>dapenDaniel</dc:creator>
    <dc:date>2020-04-08T21:45:09Z</dc:date>
    <item>
      <title>Add extra year rows in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638507#M189872</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset like below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input firmID $	Year	Value;
datalines;
A	1995	1
A	1996	1
A	1997	1
A	1998	1
B	1997	2
B	1998	2
B	1999	2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to add one more year for each firm while keeping the value the same. The expected output is below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input firmID $	Year	Value;
datalines;
A	1995	1
A	1996	1
A	1997	1
A	1998	1
&lt;FONT color="#FF0000"&gt;A   1999    1&lt;/FONT&gt;
B	1997	2
B	1998	2
B	1999	2
&lt;FONT color="#FF0000"&gt;B   2000    2&lt;/FONT&gt;
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 21:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638507#M189872</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2020-04-08T21:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Add extra year rows in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638513#M189877</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* untested */&lt;BR /&gt;&lt;BR /&gt;proc sort data=have;
by firmid year;
run;

data want;
set have;
by firmid year;
output:
if last .firmid then do;
&amp;nbsp; &amp;nbsp;year=year+1;
&amp;nbsp; &amp;nbsp;output;
end;
run;





&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data have;
input firmID $	Year	Value;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 21:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638513#M189877</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-04-08T21:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Add extra year rows in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638514#M189878</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data have;
input firmID $	Year	Value;
datalines;
A	1995	1
A	1996	1
A	1997	1
A	1998	1
B	1997	2
B	1998	2
B	1999	2
;
run;

data want;
  set have;
  by firmid;
  if last.firmid then do;
   output;
   year=year+1;
   output;
 end;
 else output;
run;&lt;/PRE&gt;
&lt;P&gt;Assumes the data is sorted by firmid and year. If not actually sorted by Firmid use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by notsorted firmid;&lt;/P&gt;
&lt;P&gt;but all of the firmid values better be one after the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An explicit OUTPUT statement writes to the data set when encountered and overrides the default "at the bottom of the data step". So you need the Else Output to get the unmodified output. The first output inside the do block writes the last record, then modifies the variable and writes the modified record.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 21:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638514#M189878</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-08T21:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Add extra year rows in panel data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638564#M189906</link>
      <description>Thanks!!!</description>
      <pubDate>Thu, 09 Apr 2020 04:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-extra-year-rows-in-panel-data/m-p/638564#M189906</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2020-04-09T04:02:49Z</dc:date>
    </item>
  </channel>
</rss>

