<?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 in gap years in my dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810093#M33816</link>
    <description>&lt;P&gt;Create a template having all country/year combinations, then update it with have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Country :$20. Year Disaster :$10.;
datalines;
Afghanistan 1990 Flood
Afghanistan 1993 Epidemic
Afghanistan 2020 Storm
Albania 1992 Landslide
Albania 1994 Storm
Albania 2014 Epidemic
;

data years;
do year = 1990 to 2020;
  output;
end;
run;

proc sql;
create table template as
  select distinct
    have.country,
    years.year,
    "None" as disaster length=10
  from have, years
;
quit;

data want;
update template have;
by country year;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 27 Apr 2022 09:22:17 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-04-27T09:22:17Z</dc:date>
    <item>
      <title>Fill in gap years in my dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810088#M33814</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm after some assistance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to fill in the years in between the observations in the following dataset:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
input Country $ Year Disaster $;
datalines;
Afghanistan 1990 Flood
Afghanistan 1993 Epidemic
...
Afghanistan 2020 Storm
Albania 1992 Landslide
Albania 1994 Storm
...
Albania 2014 Epidemic
...&lt;/LI-CODE&gt;&lt;P&gt;I would like to have all the observation for each country ranging from year 1990 to 2020, with a value "None" on the variable disaster for the years in which no disaster was registered. For example:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;datalines;
Afghanistan 1990 Flood
Afghanistan 1991 None
Afghanistan 1992 None
Afghanistan 1993 Epidemic
...
Afghanistan 2020 Storm
Albania 1990 None
Albania 1991 None
Albania 1992 Landslide
Albania 1993 None
Albania 1994 Storm
...
Albania 2014 Epidemic
...
Albania 2020 None&lt;/LI-CODE&gt;&lt;P&gt;Any help would be greatly appreciated .&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 08:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810088#M33814</guid>
      <dc:creator>alsi21ac</dc:creator>
      <dc:date>2022-04-27T08:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in gap years in my dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810092#M33815</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Country $1 - 11 Year Disaster :$10.;
datalines;
Afghanistan 1990 Flood     
Afghanistan 1993 Epidemic  
Afghanistan 2020 Storm     
Albania     1992 Landslide 
Albania     1994 Storm     
Albania     2014 Epidemic  
;

data want;

   if _N_ = 1 then do;
      dcl hash h(dataset : 'have');
      h.definekey('Country', 'Year');
      h.definedata('Disaster');
      h.definedone();
   end;

   set have;
   by Country;

   if first.Country then do;
      do Year = 1990 to 2020;
         if h.find() then Disaster = 'None';
         output;
      end;
   end;
   
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Apr 2022 09:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810092#M33815</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-04-27T09:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in gap years in my dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810093#M33816</link>
      <description>&lt;P&gt;Create a template having all country/year combinations, then update it with have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Country :$20. Year Disaster :$10.;
datalines;
Afghanistan 1990 Flood
Afghanistan 1993 Epidemic
Afghanistan 2020 Storm
Albania 1992 Landslide
Albania 1994 Storm
Albania 2014 Epidemic
;

data years;
do year = 1990 to 2020;
  output;
end;
run;

proc sql;
create table template as
  select distinct
    have.country,
    years.year,
    "None" as disaster length=10
  from have, years
;
quit;

data want;
update template have;
by country year;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Apr 2022 09:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810093#M33816</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-27T09:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Fill in gap years in my dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810139#M33826</link>
      <description>&lt;P&gt;This is a case where use of a temporary array of disasters, indexed by year, and defaulting to 'None" is a nice solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Country $ Year Disaster :$9.;
datalines;
Afghanistan 1990 Flood
Afghanistan 1993 Epidemic
Afghanistan 2020 Storm
Albania 1992 Landslide
Albania 1994 Storm
run;

data want;
  set have;
  by country;
  array dhist {1990:2020} $9 _temporary_ (31*'None');
  dhist{year}=disaster;
  if last.country then do year=1990 to 2020;
    disaster=dhist{year};
    output;
    dhist{year}='None';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The &lt;EM&gt;&lt;STRONG&gt;_temporary_&lt;/STRONG&gt;&lt;/EM&gt; array will have its values (i.e. mostly a series of 'None') retained from one observation to the next.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Apr 2022 20:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Fill-in-gap-years-in-my-dataset/m-p/810139#M33826</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-27T20:13:19Z</dc:date>
    </item>
  </channel>
</rss>

