<?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 aggregate weekly data to monthly data (to make dataset smaller) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584222#M166337</link>
    <description>&lt;P&gt;I have a data set with weekly case counts of a disease by municipality by country. I need to aggregate it to monthly case counts to reduce the number of observations for future analysis. I've looked around and can't get the various tips to work for me. Any advise? I currently have 200,000 observations and I need to reduce them, thus the desire to have a data set by monthly counts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Variables I have&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;country - character, 3 levels&lt;/P&gt;&lt;P&gt;municipality - character, ~6000 levels&lt;/P&gt;&lt;P&gt;date - numeric, MMDDYY10.&lt;/P&gt;&lt;P&gt;cases, numeric&lt;/P&gt;&lt;P&gt;habitat, character, 5 levels&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; *taking weekly data and aggregating to monthly;
create table monthly as 
		select id,country,month,date,habitat,SUM(cases) 
	as Monthly_cases
FROM weekly *name of dataset;
	GROUP BY ID,DATE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Running this code still leaves me with the 200,000 observations...&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2019 13:31:55 GMT</pubDate>
    <dc:creator>natbee</dc:creator>
    <dc:date>2019-08-27T13:31:55Z</dc:date>
    <item>
      <title>aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584222#M166337</link>
      <description>&lt;P&gt;I have a data set with weekly case counts of a disease by municipality by country. I need to aggregate it to monthly case counts to reduce the number of observations for future analysis. I've looked around and can't get the various tips to work for me. Any advise? I currently have 200,000 observations and I need to reduce them, thus the desire to have a data set by monthly counts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Variables I have&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;country - character, 3 levels&lt;/P&gt;&lt;P&gt;municipality - character, ~6000 levels&lt;/P&gt;&lt;P&gt;date - numeric, MMDDYY10.&lt;/P&gt;&lt;P&gt;cases, numeric&lt;/P&gt;&lt;P&gt;habitat, character, 5 levels&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; *taking weekly data and aggregating to monthly;
create table monthly as 
		select id,country,month,date,habitat,SUM(cases) 
	as Monthly_cases
FROM weekly *name of dataset;
	GROUP BY ID,DATE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Running this code still leaves me with the 200,000 observations...&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584222#M166337</guid>
      <dc:creator>natbee</dc:creator>
      <dc:date>2019-08-27T13:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584223#M166338</link>
      <description>&lt;P&gt;Are you trying to group by month and date? Or just by date? By Country and Date? What happens if you change your GROUP BY statement to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;GROUP&lt;/SPAN&gt; &lt;SPAN class="token statement"&gt;BY&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;COUNTRY&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&amp;nbsp;MONTH&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;(I'm assuming from your existing code that you already have MONTH available as a variable. If I have misunderstood, let me know!)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right now, you have ID in your group by statement. Assuming ID is unique for each observation, that would mean nothing is being grouped.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584223#M166338</guid>
      <dc:creator>clambert22</dc:creator>
      <dc:date>2019-08-27T13:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584226#M166341</link>
      <description>&lt;P&gt;Since calendar weeks usually span over month borders, you can't do that. To do this reliably, you would need daily data.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584226#M166341</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-27T13:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584230#M166345</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286824"&gt;@natbee&lt;/a&gt;&amp;nbsp;welcome to the SAS Community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide an example of what your data looks like? Makes it much easier to provide a usable code answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584230#M166345</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T13:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584231#M166346</link>
      <description>&lt;P&gt;ahh ok. I'd ideally like things grouped by Country and Month. I will try your suggestion.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584231#M166346</guid>
      <dc:creator>natbee</dc:creator>
      <dc:date>2019-08-27T13:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584232#M166347</link>
      <description>&lt;P&gt;ahhhhhhh. That makes sense. I do have daily data available. I'll try that out, thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584232#M166347</guid>
      <dc:creator>natbee</dc:creator>
      <dc:date>2019-08-27T13:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584236#M166350</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286824"&gt;@natbee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;ahhhhhhh. That makes sense. I do have daily data available. I'll try that out, thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you can calculate a month variable on the fly if you do not already have one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table monthly as 
select
  id, country, habitat, month(date) as month, /* group variables */
  SUM(cases) as Monthly_cases /* summation */
from daily
group by id, country, habitat, calculated month /* group variables, need to be same as above */
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that all non-summarized columns need to be part of the group by clause, or SAS will do a re-merge.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 13:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584236#M166350</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-27T13:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584243#M166355</link>
      <description>&lt;P&gt;An alternative is to use an appropriate format in PROC SUMMARY. Needless to say, I can't see your data so this is untested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=daily nway;
    class id country habitat date;
    var cases;
    format date monyy7.;
    output out=monthly(drop=_TYPE_ _FREQ_) sum=Monthly_cases;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Aug 2019 14:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584243#M166355</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-27T14:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: aggregate weekly data to monthly data (to make dataset smaller)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584281#M166373</link>
      <description>&lt;P&gt;Weeks are always the same length and comparable week over week.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A month is a non standard unit that should not be used for analysis IMO - use 30 day intervals if needed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;200k observations is not a lot at all and I would strongly recommend against aggregation solely to have smaller data. If you chose to analyze at a monthly level that would also be wrong so I strongly recommend using a bi-weekly or 3 day intervals instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you running into processing issues that make you think you need to reduce the size of your data set?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286824"&gt;@natbee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data set with weekly case counts of a disease by municipality by country. I need to aggregate it to monthly case counts to reduce the number of observations for future analysis. I've looked around and can't get the various tips to work for me. Any advise? I currently have 200,000 observations and I need to reduce them, thus the desire to have a data set by monthly counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Variables I have&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;country - character, 3 levels&lt;/P&gt;
&lt;P&gt;municipality - character, ~6000 levels&lt;/P&gt;
&lt;P&gt;date - numeric, MMDDYY10.&lt;/P&gt;
&lt;P&gt;cases, numeric&lt;/P&gt;
&lt;P&gt;habitat, character, 5 levels&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; *taking weekly data and aggregating to monthly;
create table monthly as 
		select id,country,month,date,habitat,SUM(cases) 
	as Monthly_cases
FROM weekly *name of dataset;
	GROUP BY ID,DATE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Running this code still leaves me with the 200,000 observations...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 15:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/aggregate-weekly-data-to-monthly-data-to-make-dataset-smaller/m-p/584281#M166373</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-27T15:56:16Z</dc:date>
    </item>
  </channel>
</rss>

