<?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: Add observations to data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546624#M151371</link>
    <description>&lt;P&gt;My data actually has more variables in addition to these 3 variables. What if I want to keep all of the rest variables together with the three variables when creating these new observations?&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2019 18:27:13 GMT</pubDate>
    <dc:creator>mkt_apprentice</dc:creator>
    <dc:date>2019-03-27T18:27:13Z</dc:date>
    <item>
      <title>Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546616#M151364</link>
      <description>&lt;P&gt;Hello SAS communities,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp;day&amp;nbsp; drinks&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The study lasts 5 days, and days a person doesn't have any drink (drink = 0) are not reported in the data. How could I create these observations (drink = 0 in the days the person doesn't drink) in this data set? The data I want looks like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp;day&amp;nbsp; drinks&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546616#M151364</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T17:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546617#M151365</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id   day  drinks;
cards;
1     2      1
1     3      3
1     5      4
2     3      1
3     2      1
3     4      2
;

data want;
if _n_=1 then do;
dcl hash H (dataset:'have') ;
   h.definekey  ("id",'day') ;
   h.definedata ("drinks") ;
   h.definedone () ;
end;
set have(keep=id);;
by id;/*assuming it's sorted by id as your sample suggests*/
if first.id;
do day=1 to 5;
rc=h.find();
if rc ne 0 then drinks=0;
output;
end;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546617#M151365</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T17:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546618#M151366</link>
      <description>&lt;P&gt;Thanks a lot! I will try and update the results if it works.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 17:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546618#M151366</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T17:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546624#M151371</link>
      <description>&lt;P&gt;My data actually has more variables in addition to these 3 variables. What if I want to keep all of the rest variables together with the three variables when creating these new observations?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 18:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546624#M151371</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T18:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546625#M151372</link>
      <description>&lt;P&gt;The code you wrote works. However, it only keeps the 3 variables (as I posted a simplified version of my data). The other variables are just demographics and do not change in different days. How could I keep all of them when I create new observations = 0?&amp;nbsp;&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>Wed, 27 Mar 2019 18:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546625#M151372</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T18:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546638#M151378</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203915"&gt;@mkt_apprentice&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Include you other variables in definedata like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;   h&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;definedata &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"drinks","var1","var2"....and so on up to "varn"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Also add this statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do day=1 to 5;
rc=h.find();
if rc ne 0 then do; 
drinks=0;
call missing(var1,var2, .....upto varn);
output;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also please post a more representative sample so that we can avoid going back and forth.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 19:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546638#M151378</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T19:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546675#M151397</link>
      <description>&lt;P&gt;Thanks. Can you rewrite the whole code in one block? I added the part you suggested and the variables to keep the old ones. SAS returns that&amp;nbsp;There was 1 unclosed DO block.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 20:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546675#M151397</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T20:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546685#M151401</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203915"&gt;@mkt_apprentice&lt;/a&gt;&amp;nbsp; Please review the revised sample below. You will get it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Added additional variables to the sample HAVE*/
data have;
input id   day  drinks ;
blah=rand('integer',1,100);
blahblah=rand('integer',1,100);
blahblahblah=rand('integer',1,100);
cards;
1     2      1
1     3      3
1     5      4
2     3      1
3     2      1
3     4      2
;

data want;
if _n_=1 then do;
dcl hash H (dataset:'have') ;
   h.definekey  ("id",'day') ;
   h.definedata ("drinks",'blah','blahblah','blahblahblah') ;
   h.definedone () ;
end;
set have(keep=id);;
by id;/*assuming it's sorted by id as your sample suggests*/
if first.id;
do day=1 to 5;
rc=h.find();
if rc ne 0 then do; 
drinks=0;
call missing(blah,blahblah,blahblahblah);
end;
output;
end;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 20:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546685#M151401</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T20:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546699#M151409</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; for providing data in usable form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to solve the issue:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id;
    
    length expectedDay backupDay backupDrinks 8;
    retain expectedDay;
    drop expectedDay backupDay backupDrinks;
    
    if first.id then do;
        expectedDay = 1;
    end;
    
    if day ^= expectedDay then do;
        backupDay = day;
        backupDrinks = drinks;
        drinks = 0;
        
        do day = expectedDay to backupDay-1;
            output;
        end;
        
        drinks = backupDrinks;
    end;
    
    output;
    
    expectedDay = day + 1;
    
    if last.id and day ^= 5 then do;
        drinks = 0;
        do day = day+1 to 5;
            output;
        end;
    end;
    
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 20:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546699#M151409</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-27T20:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546703#M151413</link>
      <description>&lt;P&gt;Thanks a lot for the code. Just one more thing that I need your help. The demographic variables that are associated each person (id) are not kept for the observation drinks = 0. They all become "." or missing data. Is there any way I can keep them in the newly created drinks=0 observations? I copied your code and added the demographic variables to the appropriate location in the code but the results include .&amp;nbsp;rather than these demographic variables. Can you please help?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 20:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546703#M151413</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T20:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546708#M151418</link>
      <description>&lt;P&gt;Comment out this part&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/*call &lt;SPAN class="token function"&gt;missing&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;blah&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;blahblah&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;blahblahblah&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;*/&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Complete code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Added additional variables to the sample HAVE*/
data have;
input id   day  drinks ;
blah=rand('integer',1,100);
blahblah=rand('integer',1,100);
blahblahblah=rand('integer',1,100);
cards;
1     2      1
1     3      3
1     5      4
2     3      1
3     2      1
3     4      2
;

data want;
if _n_=1 then do;
if 0 then set have;
dcl hash H (dataset:'have') ;
   h.definekey  ("id",'day') ;
   h.definedata ("drinks",'blah','blahblah','blahblahblah') ;
   h.definedone () ;
end;
set have(keep=id);;
by id;/*assuming it's sorted by id as your sample suggests*/
if first.id;
do day=1 to 5;
rc=h.find();
if rc ne 0 then do; 
drinks=0;
/*call missing(blah,blahblah,blahblahblah);*/
end;
output;
end;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546708#M151418</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T21:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546710#M151420</link>
      <description>&lt;P&gt;What does call missing do? I want these demographic variables to be the same as the ones in observations drinks differ than 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; day drinks age gender&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently the resulting data is like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; day drinks age gender&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546710#M151420</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T21:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546711#M151421</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203915"&gt;@mkt_apprentice&lt;/a&gt;&amp;nbsp; Edited the previous with complete code&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546711#M151421</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T21:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546712#M151422</link>
      <description>&lt;P&gt;It still produces .&amp;nbsp;values &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546712#M151422</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T21:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546713#M151423</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203915"&gt;@mkt_apprentice&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I owe an apology as I overlooked a minor issue. Really sorry&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please find the corrected code below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Added additional variables to the sample HAVE*/
data have;
input id   day  drinks ;
blah=rand('integer',1,100);
blahblah=rand('integer',1,100);
blahblahblah=rand('integer',1,100);
cards;
1     2      1
1     3      3
1     5      4
2     3      1
3     2      1
3     4      2
;

data want;
if _n_=1 then do;
if 0 then set have;
dcl hash H (dataset:'have',multidata:'y') ;
   h.definekey  ("id",'day') ;
   h.definedata ("drinks") ;
   h.definedone () ;
end;
set have(keep=id blah blahblah blahblahblah);
by id;/*assuming it's sorted by id as your sample suggests*/
if first.id;
do day=1 to 5;
rc=h.find();
if rc ne 0 then drinks=0;
output;
end;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546713#M151423</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T21:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546714#M151424</link>
      <description>&lt;P&gt;What do you mean in multidata: 'y'? Do I need to create a separate&amp;nbsp;data set for the demographic&amp;nbsp;variables?&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546714#M151424</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T21:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546716#M151425</link>
      <description>&lt;P&gt;No, just ignore that option. Not needed. Will work without it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Added additional variables to the sample HAVE*/
data have;
input id   day  drinks ;
blah=rand('integer',1,100);
blahblah=rand('integer',1,100);
blahblahblah=rand('integer',1,100);
cards;
1     2      1
1     3      3
1     5      4
2     3      1
3     2      1
3     4      2
;

data want;
if _n_=1 then do;
if 0 then set have;
dcl hash H (dataset:'have') ;
   h.definekey  ("id",'day') ;
   h.definedata ("drinks") ;
   h.definedone () ;
end;
set have(keep=id blah blahblah blahblahblah);
by id;/*assuming it's sorted by id as your sample suggests*/
if first.id;
do day=1 to 5;
rc=h.find();
if rc ne 0 then drinks=0;
output;
end;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546716#M151425</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T21:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546721#M151428</link>
      <description>&lt;P&gt;A BIG THANKS TO YOU!!!&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546721#M151428</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2019-03-27T21:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546722#M151429</link>
      <description>&lt;P&gt;You are welcome! have a good one!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 21:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-observations-to-data/m-p/546722#M151429</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-27T21:21:08Z</dc:date>
    </item>
  </channel>
</rss>

