<?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 id day data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512053#M2292</link>
    <description>&lt;P&gt;Another neat little trick you can do is to use the SPARSE option in PROC FREQ.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as there's a value somewhere it will be filled in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have noprint; 
table id * day / out = want sparse;
weight workout;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203915"&gt;@mkt_apprentice&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello SAS members,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with observations and variables like these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp;day&amp;nbsp; workout&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&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; 1&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So person 1 records all day (1 to 5) as the person work out every day, but person&amp;nbsp;2 and 3 don't have workout records of day&amp;nbsp;1, 3 and day 4, 5. Since no records mean no workout, I want to add in observations of 0s for those people (person 2 and 3). How can I do that without manually entering data or 0s to each observation? I have more than 5,000 people in the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Nov 2018 00:58:15 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-12T00:58:15Z</dc:date>
    <item>
      <title>Add observations to id day data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512050#M2290</link>
      <description>&lt;P&gt;Hello SAS members,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with observations and variables like these:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp;day&amp;nbsp; workout&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&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; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So person 1 records all day (1 to 5) as the person work out every day, but person&amp;nbsp;2 and 3 don't have workout records of day&amp;nbsp;1, 3 and day 4, 5. Since no records mean no workout, I want to add in observations of 0s for those people (person 2 and 3). How can I do that without manually entering data or 0s to each observation? I have more than 5,000 people in the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 23:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512050#M2290</guid>
      <dc:creator>mkt_apprentice</dc:creator>
      <dc:date>2018-11-11T23:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to id day data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512051#M2291</link>
      <description>&lt;P&gt;First, create a shell of all id/day values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table days as select distinct day from have;&lt;/P&gt;
&lt;P&gt;create table ids as select distinct id from have;&lt;/P&gt;
&lt;P&gt;create table shell as select * from days, ids order by id day;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then merge them with the actual data.&amp;nbsp; Assuming the actual data is sorted by ID DAY:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge shell have (in=have_data);&lt;/P&gt;
&lt;P&gt;by id day;&lt;/P&gt;
&lt;P&gt;if have_data=0 then workout=0;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 00:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512051#M2291</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-12T00:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to id day data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512053#M2292</link>
      <description>&lt;P&gt;Another neat little trick you can do is to use the SPARSE option in PROC FREQ.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As long as there's a value somewhere it will be filled in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have noprint; 
table id * day / out = want sparse;
weight workout;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203915"&gt;@mkt_apprentice&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello SAS members,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with observations and variables like these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp; &amp;nbsp;day&amp;nbsp; workout&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&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; 1&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&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; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So person 1 records all day (1 to 5) as the person work out every day, but person&amp;nbsp;2 and 3 don't have workout records of day&amp;nbsp;1, 3 and day 4, 5. Since no records mean no workout, I want to add in observations of 0s for those people (person 2 and 3). How can I do that without manually entering data or 0s to each observation? I have more than 5,000 people in the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 00:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512053#M2292</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-12T00:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to id day data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512057#M2294</link>
      <description>&lt;P&gt;Pretty straight forward once you know the max days&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id     day  workout ;
cards;
1      1      1
1      2      1
1      3      1
1      4      1
1      5      1
2      2      1
2      4      1
2      5      1 
3      1      1
3      2      1
3      3      1 
;

proc sql;
select max(day) into :d
from have;
quit;

data want;
array t(&amp;amp;d)_temporary_ (1:&amp;amp;d) ;
array j(&amp;amp;d) _temporary_;
call missing(of j(*));
do until(last.id);
set have;
by id;
j(day)=day;
end;
do _n_=1 to dim(t);
day=t(_n_);
workout=t(_n_)=j(_n_);
output;
end;
run;

 


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Nov 2018 02:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512057#M2294</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-12T02:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add observations to id day data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512059#M2295</link>
      <description>&lt;P&gt;using day as index instead of _n_ in the loop although no difference really as such&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
array t(&amp;amp;d)_temporary_ (1:&amp;amp;d) ;
array j(&amp;amp;d) _temporary_;
call missing(of j(*));
do until(last.id);
set have;
by id;
j(day)=day;
end;
do day=1 to dim(t);
workout=t(day)=j(day);
output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Nov 2018 02:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Add-observations-to-id-day-data/m-p/512059#M2295</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-12T02:09:47Z</dc:date>
    </item>
  </channel>
</rss>

