<?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 (Expanding) the data points that are missing and giving them value 0 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435221#M282008</link>
    <description>&lt;P&gt;This would probably work when I have to do it only one time. But (my fault forgot to mention) I have the same stituation for many many different ID codes. I try to make it work on 200 different ID codes, but later it has to be even more upscaled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 12:05:26 GMT</pubDate>
    <dc:creator>Loes</dc:creator>
    <dc:date>2018-02-08T12:05:26Z</dc:date>
    <item>
      <title>Creating (Expanding) the data points that are missing and giving them value 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435214#M282005</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to expand the data that I have for the weeks that are missing. I have weekly data and the number of purchases in a certain week. Now I want to create an observation for the weeks that are missing as the number of purchases in those weeks are 0. The data looks like the following (except I have way less missing weeks):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Year&amp;nbsp; &amp;nbsp; Week Num_purch &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 10&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp;5&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 21&amp;nbsp; &amp;nbsp;10&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 22&amp;nbsp; &amp;nbsp;3&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;...&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2016&amp;nbsp; &amp;nbsp; 51&amp;nbsp; &amp;nbsp;10&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is then:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Year&amp;nbsp; &amp;nbsp; Week&amp;nbsp; &amp;nbsp; Num_purch &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2008&amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;etc.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;Also, my data contains several years from 2008 to 2016.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no clue where to start. I think with a proc expand. Also don't know how to google on this problem, do not seem to find the same problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oh, forgot to mention, I have this not one time, but for 200 different ID codes in one time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 12:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435214#M282005</guid>
      <dc:creator>Loes</dc:creator>
      <dc:date>2018-02-08T12:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating (Expanding) the data points that are missing and giving them value 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435219#M282006</link>
      <description>&lt;P&gt;Lag an retain.&amp;nbsp; For example, and this is just pseudocode as you have not provided test data in the form of a datastep:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if lag(year)=year and lag(week) ne week then do;
    do new_week=lag(week) to week;
      output;
    end;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 11:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435219#M282006</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-08T11:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating (Expanding) the data points that are missing and giving them value 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435220#M282007</link>
      <description>&lt;P&gt;While there are several hard ways to make this happen, an easy way is to create your own shell with all the weeks and years.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data shell;&lt;/P&gt;
&lt;P&gt;num_purch=0;&lt;/P&gt;
&lt;P&gt;do year = 2008 to 2016;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do week = 1 to 52;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can merge with the data that you have.&amp;nbsp; Mention SHELL first, so values that you have overwrite the zeros:&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;&lt;/P&gt;
&lt;P&gt;by year week;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;**************** EDITED:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;GIven that you have many ID codes, I will assume the data set you have is sorted by ID:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;data shell;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;set have (keep=ID);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;by ID;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;if last.ID;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;num_purch=0;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;do year = 2008 to 2016;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; do week = 1 to 52;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Then you can merge with the data that you have.&amp;nbsp; Mention SHELL first, so values that you have overwrite the zeros:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;data want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;merge shell have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;by ID year week;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;Perhaps another way will turn out to be simpler, but this is at least a reasonable, clear way to do it.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 12:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435220#M282007</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-08T12:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating (Expanding) the data points that are missing and giving them value 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435221#M282008</link>
      <description>&lt;P&gt;This would probably work when I have to do it only one time. But (my fault forgot to mention) I have the same stituation for many many different ID codes. I try to make it work on 200 different ID codes, but later it has to be even more upscaled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 12:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435221#M282008</guid>
      <dc:creator>Loes</dc:creator>
      <dc:date>2018-02-08T12:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating (Expanding) the data points that are missing and giving them value 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435222#M282009</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Year    Week Num_purch;
cards;
2008    1    10
2008    3    4
2008    10   5
2008    21   10
2008    22   3 
;
run;
data want;
 merge have have(keep=year week rename=(year=_year week=_week) firstobs=2);
 output;
 if year=_year then do;
  do i=week+1 to _week-1;
   week=i;Num_purch=0;output;
  end;
 end;
 drop _: i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 12:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435222#M282009</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-02-08T12:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating (Expanding) the data points that are missing and giving them value 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435226#M282010</link>
      <description>Thank you! This works for now. Although I deleted the num_purch=0, and after merging changed the missing values to 0. That seems to work better in my case &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; .</description>
      <pubDate>Thu, 08 Feb 2018 12:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Expanding-the-data-points-that-are-missing-and-giving/m-p/435226#M282010</guid>
      <dc:creator>Loes</dc:creator>
      <dc:date>2018-02-08T12:25:48Z</dc:date>
    </item>
  </channel>
</rss>

