<?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 Summing monthly variables until a given date is reached in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/230640#M41855</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset at the person level with an ID variable, a date variable, and several monthly count variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;Date &amp;nbsp; &amp;nbsp; &amp;nbsp;mth_200201 &amp;nbsp; &amp;nbsp; &amp;nbsp;mth_200202 &amp;nbsp; &amp;nbsp; &amp;nbsp;mth_200203...mth_201501&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/5/2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2/13/2007 &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/8/2002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is create a total variable which is a sum of the values in mth_200201 through the mth_ variable corresponding with the date (so for ID 3 above, through mth_200203 for a total of 1+3+1=5).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Oct 2015 19:51:18 GMT</pubDate>
    <dc:creator>Walternate</dc:creator>
    <dc:date>2015-10-19T19:51:18Z</dc:date>
    <item>
      <title>Summing monthly variables until a given date is reached</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/230640#M41855</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset at the person level with an ID variable, a date variable, and several monthly count variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;Date &amp;nbsp; &amp;nbsp; &amp;nbsp;mth_200201 &amp;nbsp; &amp;nbsp; &amp;nbsp;mth_200202 &amp;nbsp; &amp;nbsp; &amp;nbsp;mth_200203...mth_201501&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/5/2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2/13/2007 &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/8/2002 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is create a total variable which is a sum of the values in mth_200201 through the mth_ variable corresponding with the date (so for ID 3 above, through mth_200203 for a total of 1+3+1=5).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 19:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/230640#M41855</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2015-10-19T19:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Summing monthly variables until a given date is reached</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/230643#M41856</link>
      <description>&lt;P&gt;Walternate,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one way to approach the problem.&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;total=0;&lt;/P&gt;
&lt;P&gt;array m {157} mth_200201 mth_200202 mth_200203 ... mth_201501;&lt;/P&gt;
&lt;P&gt;if date &amp;gt;= '01jan2002'd then do i=1 to 157 until (vname(m{i}) = 'mth_' || put( intnx('month', '01jan2002'd, i-1), yymmn6.) );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; total + m{i};&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;Some of the statements could be broken out into smaller pieces, but the logic should work as is.&amp;nbsp; (It's untested.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2015 20:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/230643#M41856</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-19T20:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Summing monthly variables until a given date is reached</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/230691#M41880</link>
      <description>&lt;P&gt;As has been mentioned above, and this seems to be a common theme, keeping data (that being the 200202/200203 etc) in column names is not a good idea. &amp;nbsp;It makes working with that data so much harder. &amp;nbsp;A better idea is to normalise your data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; MONTH &amp;nbsp; &amp;nbsp;RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/5/2013 &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;1/5/2013 &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason is that working with the MONTH is now a simple process of using a data column. &amp;nbsp;You can use all kinds of aggregates on the data, and if at some point there is a need for an output of transposed data, then call a proc transpose. &amp;nbsp;Your "working" data structure does not need to reflect your "output" data structure.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2015 08:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/230691#M41880</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-20T08:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Summing monthly variables until a given date is reached</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/231157#M42024</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply. I tried it and it worked; the problem is that I only want it to sum for people whose values of date aren't missing. So I tried this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if date&amp;nbsp;ne . then do;&lt;BR /&gt;total=0;&lt;BR /&gt;array m{157} mth_200201--mth201501;&lt;BR /&gt;do i=1 to 157 until&lt;BR /&gt;(vname(m{i})=cats('mth', year(date), month(date)));&lt;BR /&gt;total+m{i};&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I said, the code did exactly what I wanted it to for people with values of date. The problem is that there are people who are missing values of date whom I don't want to have values of total. The code as it is now is retaining the value of total for each person with a value of date and filling it in for each person with missing date until the next person with a value for date is reached. I need a way to leave total blank for those who are missing date (I thought that was what the subsetting if statement at the beginning was supposed to do, but I could be wrong...).&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 13:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/231157#M42024</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2015-10-22T13:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Summing monthly variables until a given date is reached</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/231296#M42055</link>
      <description>&lt;P&gt;Well, in the code I posted you could just switch from (total=0;) to (total=.;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That should be sufficient. &amp;nbsp;The loop only executes when date is within range (so not for missing dates). &amp;nbsp;So TOTAL would remain missing if DATE is missing. &amp;nbsp;And the sum statements (total + some_value) should work even if TOTAL starts out being missing.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 02:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summing-monthly-variables-until-a-given-date-is-reached/m-p/231296#M42055</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-23T02:19:42Z</dc:date>
    </item>
  </channel>
</rss>

