<?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 Zero Values Into Ordered Table for Cumulative Sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59714#M12940</link>
    <description>Something like the following may work for you (although I don't have a complete picture of your situation):&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
*** get all of the ID's crossed by the available years ***;&lt;BR /&gt;
&lt;BR /&gt;
proc freq data=MAIN noprint;&lt;BR /&gt;
table location_id*year / out=id_year sparse;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*** generate 12 months for each ID and Year combination ***;&lt;BR /&gt;
&lt;BR /&gt;
data zeros;&lt;BR /&gt;
  set id_year(keep=location_id year);&lt;BR /&gt;
  do month=1 to 12;&lt;BR /&gt;
    temp_total=0;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*** this is unnecessary if already sorted ***;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=MAIN out=sorted;&lt;BR /&gt;
by location_id year month;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*** fill in the holes ***;&lt;BR /&gt;
&lt;BR /&gt;
data expanded;&lt;BR /&gt;
  merge zeros sorted; by location_id year month;&lt;BR /&gt;
  total = sum( total, temp_total);&lt;BR /&gt;
drop temp_total;&lt;BR /&gt;
run;</description>
    <pubDate>Wed, 29 Jul 2009 12:48:22 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-07-29T12:48:22Z</dc:date>
    <item>
      <title>Insert Zero Values Into Ordered Table for Cumulative Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59712#M12938</link>
      <description>I've been trying to explore different ways to insert values of zero into a table where there is a missing year/month.  The table is ordered by a location ID, year, and month, &lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;Example:&lt;/U&gt;&lt;BR /&gt;
location_id  year  month  total&lt;BR /&gt;
273            2009    1         11&lt;BR /&gt;
273            2009    2         30&lt;BR /&gt;
273            2009    4         5&lt;BR /&gt;
273            2009    5         27&lt;BR /&gt;
&lt;BR /&gt;
So in this example I would need to insert a new row of: &lt;B&gt;273  2009  3  0&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
I need to loop through every row in this (much larger) table and insert a value of zero for 'total' for each missing year and month for every location_id.  I can always re-sort the table so appending at the end is acceptable.  This seems like a simple loop with some variable checking.  I'm not the best at SAS syntax but I do understand programming logic.&lt;BR /&gt;
&lt;BR /&gt;
From here I plan on finding the cumulative sum.  This is the goal I need to achieve, simply finding the cumulative sum per location_id per year/month.  And obviously having a missing month will result in a missing cumulative sum, which is the purpose for inserting rows with total=0.&lt;BR /&gt;
&lt;BR /&gt;
Any help is much appreciated!</description>
      <pubDate>Wed, 29 Jul 2009 03:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59712#M12938</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-07-29T03:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Zero Values Into Ordered Table for Cumulative Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59713#M12939</link>
      <description>Suggest you share info (an example) about your INPUT and desired OUTPUT data file structures and observations, including any existing SAS code you have as well as SAS variable information.  This additional info will help achieve a most useful  reply from subscribers.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 29 Jul 2009 05:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59713#M12939</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-29T05:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Zero Values Into Ordered Table for Cumulative Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59714#M12940</link>
      <description>Something like the following may work for you (although I don't have a complete picture of your situation):&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
*** get all of the ID's crossed by the available years ***;&lt;BR /&gt;
&lt;BR /&gt;
proc freq data=MAIN noprint;&lt;BR /&gt;
table location_id*year / out=id_year sparse;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*** generate 12 months for each ID and Year combination ***;&lt;BR /&gt;
&lt;BR /&gt;
data zeros;&lt;BR /&gt;
  set id_year(keep=location_id year);&lt;BR /&gt;
  do month=1 to 12;&lt;BR /&gt;
    temp_total=0;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*** this is unnecessary if already sorted ***;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=MAIN out=sorted;&lt;BR /&gt;
by location_id year month;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
*** fill in the holes ***;&lt;BR /&gt;
&lt;BR /&gt;
data expanded;&lt;BR /&gt;
  merge zeros sorted; by location_id year month;&lt;BR /&gt;
  total = sum( total, temp_total);&lt;BR /&gt;
drop temp_total;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 29 Jul 2009 12:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59714#M12940</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-29T12:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Zero Values Into Ordered Table for Cumulative Sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59715#M12941</link>
      <description>Actually this is &lt;B&gt;EXACTLY&lt;/B&gt; what I was looking for.  Thanks a bunch!</description>
      <pubDate>Wed, 29 Jul 2009 13:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-Zero-Values-Into-Ordered-Table-for-Cumulative-Sum/m-p/59715#M12941</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-07-29T13:08:04Z</dc:date>
    </item>
  </channel>
</rss>

