<?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: Insert missing ID from list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-missing-ID-from-list/m-p/607125#M176395</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
     input year  ID $ shock;
     cards;
     2000  1001  1
     2001  1001  1
     2002  1001  1
     2003  1001  1
     2004  1001  1
     2000  1003  1
     2001  1003  1
     2002  1003  1
     2003  1003  1
     2004  1003  1
     2000  1007  1
     2001  1007  1
     2002  1007  1
     2003  1007  1
     2004  1007  1
     2000  1010  1
     2001  1010  1
     2002  1010  1
     2003  1010  1
     2004  1010  1
;
run;

data list;
     input  ID $;
     cards;
1001
1003
1004
1005
1007
1009
1010
;
run;


data want;
merge have(in=a) list(in=b);
by id;
if a then output;
else if b then do;
shock=0;
 do year=2000 to 2004;;
 output;
end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 25 Nov 2019 20:53:51 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-11-25T20:53:51Z</dc:date>
    <item>
      <title>Insert missing ID from list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-missing-ID-from-list/m-p/607109#M176385</link>
      <description>&lt;P&gt;Say I have the following excerpt dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
     input year  ID $ shock;
     cards;
     2000  1001  1
     2001  1001  1
     2002  1001  1
     2003  1001  1
     2004  1001  1
     2000  1003  1
     2001  1003  1
     2002  1003  1
     2003  1003  1
     2004  1003  1
     2000  1007  1
     2001  1007  1
     2002  1007  1
     2003  1007  1
     2004  1007  1
     2000  1010  1
     2001  1010  1
     2002  1010  1
     2003  1010  1
     2004  1010  1	 
;
run;&lt;/PRE&gt;
&lt;P&gt;The year is always from 2000 to 2004. Shock always takes a value of 1 in this dataset. Now I have a list of IDs as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data list;
     input  ID;
     cards;
1001
1003
1004
1005
1007
1009
1010 
;
run;&lt;/PRE&gt;
&lt;P&gt;As you can see, ID 1004, 1005, and 1009 are missing from the original dataset. What I wish to do is obtain the following dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
     input year  ID $ shock;
     cards;
     2000  1001  1
     2001  1001  1
     2002  1001  1
     2003  1001  1
     2004  1001  1
     2000  1003  1
     2001  1003  1
     2002  1003  1
     2003  1003  1
     2004  1003  1
     2000  1004  0
     2001  1004  0
     2002  1004  0
     2003  1004  0
     2004  1004  0
     2000  1005  0
     2001  1005  0
     2002  1005  0
     2003  1005  0
     2004  1005  0
     2000  1007  1
     2001  1007  1
     2002  1007  1
     2003  1007  1
     2004  1007  1
     2000  1009  0
     2001  1009  0
     2002  1009  0
     2003  1009  0
     2004  1009  0
     2000  1010  1
     2001  1010  1
     2002  1010  1
     2003  1010  1
     2004  1010  1	 
;
run;&lt;/PRE&gt;
&lt;P&gt;So that the missing IDs are inserted into the original dataset from year 2000 to 2004 but shock takes a value of 0 for these missing IDs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 20:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-missing-ID-from-list/m-p/607109#M176385</guid>
      <dc:creator>TrueTears</dc:creator>
      <dc:date>2019-11-25T20:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Insert missing ID from list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-missing-ID-from-list/m-p/607111#M176386</link>
      <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
     input year  ID $ shock;
     cards;
     2000  1001  1
     2001  1001  1
     2002  1001  1
     2003  1001  1
     2004  1001  1
     2000  1003  1
     2001  1003  1
     2002  1003  1
     2003  1003  1
     2004  1003  1
     2000  1007  1
     2001  1007  1
     2002  1007  1
     2003  1007  1
     2004  1007  1
     2000  1010  1
     2001  1010  1
     2002  1010  1
     2003  1010  1
     2004  1010  1
;
run;

data list;
     input  ID $;
     cards;
1001
1003
1004
1005
1007
1009
1010
;
run;

data want;
   if _N_=1 then do;
      dcl hash h(dataset:'have');
      h.definekey('ID');
      h.definedone();
   end;

   set list;

   do year=2000 to 2004;
      shock=ifn(h.check(), 0, 1);
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID   year shock 
1001 2000 1 
1001 2001 1 
1001 2002 1 
1001 2003 1 
1001 2004 1 
1003 2000 1 
1003 2001 1 
1003 2002 1 
1003 2003 1 
1003 2004 1 
1004 2000 0 
1004 2001 0 
1004 2002 0 
1004 2003 0 
1004 2004 0 
1005 2000 0 
1005 2001 0 
1005 2002 0 
1005 2003 0 
1005 2004 0 
1007 2000 1 
1007 2001 1 
1007 2002 1 
1007 2003 1 
1007 2004 1 
1009 2000 0 
1009 2001 0 
1009 2002 0 
1009 2003 0 
1009 2004 0 
1010 2000 1 
1010 2001 1 
1010 2002 1 
1010 2003 1 
1010 2004 1 
&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Nov 2019 20:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-missing-ID-from-list/m-p/607111#M176386</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-25T20:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Insert missing ID from list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-missing-ID-from-list/m-p/607125#M176395</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
     input year  ID $ shock;
     cards;
     2000  1001  1
     2001  1001  1
     2002  1001  1
     2003  1001  1
     2004  1001  1
     2000  1003  1
     2001  1003  1
     2002  1003  1
     2003  1003  1
     2004  1003  1
     2000  1007  1
     2001  1007  1
     2002  1007  1
     2003  1007  1
     2004  1007  1
     2000  1010  1
     2001  1010  1
     2002  1010  1
     2003  1010  1
     2004  1010  1
;
run;

data list;
     input  ID $;
     cards;
1001
1003
1004
1005
1007
1009
1010
;
run;


data want;
merge have(in=a) list(in=b);
by id;
if a then output;
else if b then do;
shock=0;
 do year=2000 to 2004;;
 output;
end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Nov 2019 20:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-missing-ID-from-list/m-p/607125#M176395</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-25T20:53:51Z</dc:date>
    </item>
  </channel>
</rss>

