<?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: Creating new observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273093#M54397</link>
    <description>&lt;P&gt;"&lt;SPAN&gt;I could create a day for each animal in a separate file and merge the two&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless you have millions of animals, or you are doing this for free, this is the most efficient way to go about it.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 May 2016 18:04:24 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-05-25T18:04:24Z</dc:date>
    <item>
      <title>Creating new observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273080#M54394</link>
      <description>&lt;P&gt;(SAS 9.4) I am working with a fairly large data set and have data on numerous animals. I have about 100 days of data for each animal and want to create a data set that has observations for each day, regardless of if i actually have data on those days (all of my other variables would be missing). For example, I want an observation for each day (day 0 through day 100) for each animal in my data set (each day for each animal is different). I know I could create a day for each animal in a separate file and merge the two, but this will be rather timely. Is there a way I can take my existing data sheet and have SAS look through the dates (I also have a variable that courresponds to the date that is just the day, such as day 1, day 2, etc) and add in observations when the data skips a day?&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273080#M54394</guid>
      <dc:creator>llt34c</dc:creator>
      <dc:date>2016-05-25T17:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273089#M54395</link>
      <description>&lt;P&gt;You can use PROC EXPAND but this requires SAS/ETS license.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_tsdata_sect045.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_tsdata_sect045.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273089#M54395</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-25T17:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273091#M54396</link>
      <description>&lt;P&gt;Okay, thanks for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 17:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273091#M54396</guid>
      <dc:creator>llt34c</dc:creator>
      <dc:date>2016-05-25T17:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273093#M54397</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;I could create a day for each animal in a separate file and merge the two&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless you have millions of animals, or you are doing this for free, this is the most efficient way to go about it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 18:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273093#M54397</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-05-25T18:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273102#M54402</link>
      <description>&lt;P&gt;It's clumsy, but it can be done.&amp;nbsp; Here's an approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by animal day;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by animal day;&lt;/P&gt;
&lt;P&gt;array chars {*} _character_;&lt;/P&gt;
&lt;P&gt;array nums {*} _numeric_;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;prior_day = lag(day);&lt;/P&gt;
&lt;P&gt;copy_of_animal = animal;&lt;/P&gt;
&lt;P&gt;copy_of_day = day;&lt;/P&gt;
&lt;P&gt;call missing (of chars{*});&lt;/P&gt;
&lt;P&gt;call missing (of nums{*});&lt;/P&gt;
&lt;P&gt;animal = copy_of_animal;&lt;/P&gt;
&lt;P&gt;if first.animal and copy_of_day &amp;gt; 1 then do day=1 to copy_of_day-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else if copy_of_day &amp;gt; prior_day + 1 then do day=prior_day+1 to copy_of_day-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if last.animal and copy_of_day &amp;lt; 100 then do day = copy_of_day + 1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop copy_of_day copy_of_animal prior_day;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to re-sort the observations afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You said you had 100 days of data per animal, but also said that DAY goes from 0 to 100.&amp;nbsp; Those two are actually slightly different, so I assumed that DAY should go from 1 to 100.&amp;nbsp; Minimal change would be required to go from 0 to 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is untested, but likely to work as is.&amp;nbsp; It does assume that DAY is numeric.&amp;nbsp; Good luck.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 18:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-new-observations/m-p/273102#M54402</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-25T18:38:12Z</dc:date>
    </item>
  </channel>
</rss>

