<?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: How do I accumulate monthly values into a single yearly observation? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602247#M174330</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/287373"&gt;@rsiddh2&lt;/a&gt;&amp;nbsp; &amp;nbsp;Not sure why there would be a need for loops, if my understanding is correct and the below is perhaps what you are after?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select year(date) as year, sum(import) as total
from your_dataset
group by year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Nov 2019 22:02:45 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-11-06T22:02:45Z</dc:date>
    <item>
      <title>How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602241#M174328</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with a raw dataset regarding U.S. foreign trade that includes a list of monthly export and import values from 1987 to 2015. I'm trying to create a new dataset that lists the total import values for each year. I've tried using do loops, first. and last. statements, but to no avail. After reading in the raw dataset, here is a sample screenshot.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-06 at 3.58.09 PM.png" style="width: 353px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33728i00E1B6A17E267B92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2019-11-06 at 3.58.09 PM.png" alt="Screen Shot 2019-11-06 at 3.58.09 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to have a dataset that lists the year and its corresponding total import values. How should I go about this? Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 21:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602241#M174328</guid>
      <dc:creator>rsiddh2</dc:creator>
      <dc:date>2019-11-06T21:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602247#M174330</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/287373"&gt;@rsiddh2&lt;/a&gt;&amp;nbsp; &amp;nbsp;Not sure why there would be a need for loops, if my understanding is correct and the below is perhaps what you are after?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select year(date) as year, sum(import) as total
from your_dataset
group by year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602247#M174330</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-06T22:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602248#M174331</link>
      <description>&lt;P&gt;So Output would look similar to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1987 | 345,990.70&lt;/P&gt;
&lt;P&gt;1988 | 324,383.90&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602248#M174331</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-06T22:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602249#M174332</link>
      <description>Correct.</description>
      <pubDate>Wed, 06 Nov 2019 22:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602249#M174332</guid>
      <dc:creator>rsiddh2</dc:creator>
      <dc:date>2019-11-06T22:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602250#M174333</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;posted the solution then.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602250#M174333</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-06T22:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602252#M174335</link>
      <description>Thank you! As a side note, is it possible to accomplish this using a data step? There are additional things I wish to perform with this new data.</description>
      <pubDate>Wed, 06 Nov 2019 22:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602252#M174335</guid>
      <dc:creator>rsiddh2</dc:creator>
      <dc:date>2019-11-06T22:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602253#M174336</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set your_dataset;
year=year(date);
run;

data want;
set temp;
by year;
if first.year then total=import;
else total+import;
if last.year;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602253#M174336</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-06T22:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602255#M174337</link>
      <description>&lt;P&gt;Use PROC MEANS or a Summary Task (via the point and click interface) to add up the data to each year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apply a format to the date variable as a year to get the annual values.&lt;/P&gt;
&lt;P&gt;Here's an example using the stock data aggregated to years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=sashelp.stocks N NMISS min max mean median STACKODS;
class date;
format date year4.;
var open high low;
output out=want n= mean= sum= median= mean= / autoname autolabel;
ods output summary = want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/287373"&gt;@rsiddh2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working with a raw dataset regarding U.S. foreign trade that includes a list of monthly export and import values from 1987 to 2015. I'm trying to create a new dataset that lists the total import values for each year. I've tried using do loops, first. and last. statements, but to no avail. After reading in the raw dataset, here is a sample screenshot.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-06 at 3.58.09 PM.png" style="width: 353px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33728i00E1B6A17E267B92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2019-11-06 at 3.58.09 PM.png" alt="Screen Shot 2019-11-06 at 3.58.09 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to have a dataset that lists the year and its corresponding total import values. How should I go about this? Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602255#M174337</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-06T22:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602260#M174338</link>
      <description>&lt;P&gt;This returns a table that lists the year, but for some reason, it does not create the new total variable and the imports given are from the last month. Here is the output after running your code:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-06 at 4.45.09 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33730i830458C578859FC2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2019-11-06 at 4.45.09 PM.png" alt="Screen Shot 2019-11-06 at 4.45.09 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602260#M174338</guid>
      <dc:creator>rsiddh2</dc:creator>
      <dc:date>2019-11-06T22:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602262#M174339</link>
      <description>&lt;P&gt;I think there is perhaps a gross misunderstanding on my part on the requirement. Can you plz post a sample as plain text(not pics) and a corresponding sample of your required output&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602262#M174339</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-06T22:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602264#M174340</link>
      <description>&lt;P&gt;Here is each month in 1987 with its corresponding import values. I want to create a new data set that lists the total imports for each year from 1987 to 2015.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Month&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Imports&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;January 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30,798.5&lt;/P&gt;&lt;P&gt;February 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29,810.3&lt;/P&gt;&lt;P&gt;March 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 32,464.3&lt;/P&gt;&lt;P&gt;April 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32,291.1&lt;/P&gt;&lt;P&gt;May 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33,170.0&lt;/P&gt;&lt;P&gt;June 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 35,358.0&lt;/P&gt;&lt;P&gt;July 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;35,809.9&lt;/P&gt;&lt;P&gt;August 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 33,826.2&lt;/P&gt;&lt;P&gt;September 1987&amp;nbsp; &amp;nbsp;33,667.5&lt;/P&gt;&lt;P&gt;October 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 38,075.6&lt;/P&gt;&lt;P&gt;November 1987&amp;nbsp; &amp;nbsp; 35,210.9&lt;/P&gt;&lt;P&gt;December 1987&amp;nbsp; &amp;nbsp; 35,758.7&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TOTAL 1987&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;406,241.0&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 23:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602264#M174340</guid>
      <dc:creator>rsiddh2</dc:creator>
      <dc:date>2019-11-06T23:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I accumulate monthly values into a single yearly observation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602265#M174341</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/287373"&gt;@rsiddh2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you! As a side note, is it possible to accomplish this using a data step? There are additional things I wish to perform with this new data.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Many times it is easier to break a problem into components, such as the total calculation, using an appropriate tool, like Proc Means and then merging the result together instead of attempting to force everything through a single data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And it may not hurt to describe what some of those "additional things" might be. For instance your picture of the data shows two other variables, Export and Balance. If I wanted to get sums of those I would use &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s solution adding Export and Balance to the VAR statement and get the statistics for all 3 variables at one pass.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you happened to have another variable such as Country the trade was with then you could add a CLASS statement to Proc Means/ or Summary with that variable and you would get the summary by country as well as an overall total.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 23:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-accumulate-monthly-values-into-a-single-yearly/m-p/602265#M174341</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-06T23:01:20Z</dc:date>
    </item>
  </channel>
</rss>

