<?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 Create cummulative overview in 1 step in stead of several steps / procs...? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57926#M16160</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I've got a question again! Should be simple (I think...), but not for me...&lt;BR /&gt;
&lt;BR /&gt;
I've got a dataset with dates (so including full daynumbers) beginning at 2008, including amounts and intems. What I want is a cummulative overview &lt;B&gt;per month&lt;/B&gt; of the data (so at the end of all periods a total of sold items including a total of the bucks / EUR / $). Little example:&lt;BR /&gt;
&lt;BR /&gt;
Date (DMY)   Amount     Number&lt;BR /&gt;
01-01-2008        10             5&lt;BR /&gt;
01-01-2008        15             7&lt;BR /&gt;
02-02-2008          9             4&lt;BR /&gt;
05-02-2008        15             6&lt;BR /&gt;
01-01-2009        20            10&lt;BR /&gt;
01-01-2009          1             1&lt;BR /&gt;
05-06-2009          3             2&lt;BR /&gt;
04-06-2010        20             8&lt;BR /&gt;
01-01-2010        25            12&lt;BR /&gt;
&lt;BR /&gt;
And I want my output something like:&lt;BR /&gt;
&lt;BR /&gt;
01-01-2008        25            13&lt;BR /&gt;
02-02-2008        24            10&lt;BR /&gt;
01-01-2009        21            11&lt;BR /&gt;
05-06-2009        23            10&lt;BR /&gt;
01-01-2010        25            12&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
When I try something like this, I have to use at least 2 datasteps: to gether the data, to format the data, to create extra variables, and to create a proc report including an "out" statement.&lt;BR /&gt;
&lt;BR /&gt;
If it is possible (what I think, do loops?), I do want to have this process in 1 datastep. Does anyone have any idea? Thanks for your input in advance!!&lt;BR /&gt;
&lt;BR /&gt;
Data test1;&lt;BR /&gt;
set X;&lt;BR /&gt;
format sldo_ultmo_per_bkng comma12.;&lt;BR /&gt;
datum = former_datetime/86400;&lt;BR /&gt;
format datum comma12.;&lt;BR /&gt;
_year=year(datum); _month=month(datum);&lt;BR /&gt;
counter=1; * --&amp;gt; to compute the number of items in the proc report below...;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc report data=test1 out=test2;&lt;BR /&gt;
Columns _year _month sldo_ultmo_per_bkng counter;&lt;BR /&gt;
define Jaar / group width=20 order=internal;&lt;BR /&gt;
define Maand/ group width=20 order=internal;&lt;BR /&gt;
define sldo_ultmo_per_bkng / sum;&lt;BR /&gt;
define counter / n;&lt;BR /&gt;
run;&lt;B&gt;&lt;/B&gt;</description>
    <pubDate>Tue, 04 Jan 2011 15:28:15 GMT</pubDate>
    <dc:creator>Wouter</dc:creator>
    <dc:date>2011-01-04T15:28:15Z</dc:date>
    <item>
      <title>Create cummulative overview in 1 step in stead of several steps / procs...?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57926#M16160</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I've got a question again! Should be simple (I think...), but not for me...&lt;BR /&gt;
&lt;BR /&gt;
I've got a dataset with dates (so including full daynumbers) beginning at 2008, including amounts and intems. What I want is a cummulative overview &lt;B&gt;per month&lt;/B&gt; of the data (so at the end of all periods a total of sold items including a total of the bucks / EUR / $). Little example:&lt;BR /&gt;
&lt;BR /&gt;
Date (DMY)   Amount     Number&lt;BR /&gt;
01-01-2008        10             5&lt;BR /&gt;
01-01-2008        15             7&lt;BR /&gt;
02-02-2008          9             4&lt;BR /&gt;
05-02-2008        15             6&lt;BR /&gt;
01-01-2009        20            10&lt;BR /&gt;
01-01-2009          1             1&lt;BR /&gt;
05-06-2009          3             2&lt;BR /&gt;
04-06-2010        20             8&lt;BR /&gt;
01-01-2010        25            12&lt;BR /&gt;
&lt;BR /&gt;
And I want my output something like:&lt;BR /&gt;
&lt;BR /&gt;
01-01-2008        25            13&lt;BR /&gt;
02-02-2008        24            10&lt;BR /&gt;
01-01-2009        21            11&lt;BR /&gt;
05-06-2009        23            10&lt;BR /&gt;
01-01-2010        25            12&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
When I try something like this, I have to use at least 2 datasteps: to gether the data, to format the data, to create extra variables, and to create a proc report including an "out" statement.&lt;BR /&gt;
&lt;BR /&gt;
If it is possible (what I think, do loops?), I do want to have this process in 1 datastep. Does anyone have any idea? Thanks for your input in advance!!&lt;BR /&gt;
&lt;BR /&gt;
Data test1;&lt;BR /&gt;
set X;&lt;BR /&gt;
format sldo_ultmo_per_bkng comma12.;&lt;BR /&gt;
datum = former_datetime/86400;&lt;BR /&gt;
format datum comma12.;&lt;BR /&gt;
_year=year(datum); _month=month(datum);&lt;BR /&gt;
counter=1; * --&amp;gt; to compute the number of items in the proc report below...;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc report data=test1 out=test2;&lt;BR /&gt;
Columns _year _month sldo_ultmo_per_bkng counter;&lt;BR /&gt;
define Jaar / group width=20 order=internal;&lt;BR /&gt;
define Maand/ group width=20 order=internal;&lt;BR /&gt;
define sldo_ultmo_per_bkng / sum;&lt;BR /&gt;
define counter / n;&lt;BR /&gt;
run;&lt;B&gt;&lt;/B&gt;</description>
      <pubDate>Tue, 04 Jan 2011 15:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57926#M16160</guid>
      <dc:creator>Wouter</dc:creator>
      <dc:date>2011-01-04T15:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create cummulative overview in 1 step in stead of several steps / procs...?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57927#M16161</link>
      <description>Look at using the INTNX function and "MONTHS" for argument #1.  Also, you can consider using a SAS output format to display year/month components only.  Your code can accumulate based on the "PERIOD" derived variable:&lt;BR /&gt;
&lt;BR /&gt;
FORMAT PERIOD YYMMS7. ;&lt;BR /&gt;
PERIOD = INTNX('MONTH',&lt;DATEVAR&gt;,0);&lt;BR /&gt;
&lt;BR /&gt;
Also, PROC SUMMARY can do the summarization for you, to include an internal sort using the CLASS statement, as well generate your _FREQ_ variable, which could feed your report step, as required.  And, it's possible that PROC REPORT with GROUP can do something similar.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/DATEVAR&gt;</description>
      <pubDate>Tue, 04 Jan 2011 18:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57927#M16161</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-01-04T18:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create cummulative overview in 1 step in stead of several steps / procs...?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57928#M16162</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Please try below code and let me know...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as &lt;BR /&gt;
select b.date as date1 format=ddmmyy10., sum(amt) as amt, sum(nbr) as nbr&lt;BR /&gt;
from test a left join (select min(date) as date format=mmddyy10. from test group by month(date), year(date)) b&lt;BR /&gt;
on month(a.date)=month(b.date) and year(a.date)=year(b.date)&lt;BR /&gt;
group by b.date;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Please check once you required output that u have mentioned wrong as per your input.&lt;BR /&gt;
It might be a typo...&lt;BR /&gt;
&lt;BR /&gt;
As required monthly totals in one step , use above code.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Uday Duddu</description>
      <pubDate>Tue, 04 Jan 2011 18:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57928#M16162</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-04T18:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create cummulative overview in 1 step in stead of several steps / procs...?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57929#M16163</link>
      <description>As Udaydudu said.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Date (DMY) Amount Number&lt;BR /&gt;
01-01-2008 10 5&lt;BR /&gt;
01-01-2008 15 7&lt;BR /&gt;
02-02-2008 9 4&lt;BR /&gt;
05-02-2008 15 6&lt;BR /&gt;
01-01-2009 20 10&lt;BR /&gt;
01-01-2009 1 1&lt;BR /&gt;
&lt;B&gt;05-06-2009 3 2&lt;BR /&gt;
04-06-2010 20 8&lt;/B&gt;&lt;BR /&gt;
01-01-2010 25 12&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
01-01-2008 25 13&lt;BR /&gt;
02-02-2008 24 10&lt;BR /&gt;
01-01-2009 21 11&lt;BR /&gt;
&lt;B&gt;05-06-2009 23 10&lt;/B&gt;&lt;BR /&gt;
01-01-2010 25 12&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Is it right?&lt;BR /&gt;
And whether do you want only one data step ? or maybe consider use proc sql which has more flexibility.&lt;BR /&gt;
And the dataset is already sorted by date?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Wed, 05 Jan 2011 01:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57929#M16163</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-05T01:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create cummulative overview in 1 step in stead of several steps / procs...?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57930#M16164</link>
      <description>Ok.anyway.&lt;BR /&gt;
If you do not mind output looks like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
                                                                amount_    number_&lt;BR /&gt;
                                                       date      Sum        Sum&lt;BR /&gt;
&lt;BR /&gt;
                                                    JAN2008       25         12&lt;BR /&gt;
                                                    FEB2008       24         10&lt;BR /&gt;
                                                    JAN2009       21         11&lt;BR /&gt;
                                                    JUN2009       23         10&lt;BR /&gt;
                                                    JAN2010       25         12&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sum;&lt;BR /&gt;
 input date : ddmmyy10. amount number;&lt;BR /&gt;
datalines;&lt;BR /&gt;
01-01-2008 10 5&lt;BR /&gt;
01-01-2008 15 7&lt;BR /&gt;
02-02-2008 9 4&lt;BR /&gt;
05-02-2008 15 6&lt;BR /&gt;
01-01-2009 20 10&lt;BR /&gt;
01-01-2009 1 1&lt;BR /&gt;
05-06-2009 3 2&lt;BR /&gt;
04-06-2009 20 8&lt;BR /&gt;
01-01-2010 25 12&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc means data=sum nway;&lt;BR /&gt;
 class date;&lt;BR /&gt;
 format date monyy7.;&lt;BR /&gt;
 var amount number;&lt;BR /&gt;
 output out=result(drop= _type_ _freq_) sum= /autoname;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs;run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 06 Jan 2011 03:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57930#M16164</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-06T03:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Create cummulative overview in 1 step in stead of several steps / procs...?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57931#M16165</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Assuming your data set is sorted one solution to do it in a single data step follows:&lt;BR /&gt;
&lt;BR /&gt;
data out;&lt;BR /&gt;
set in end=z;&lt;BR /&gt;
&lt;BR /&gt;
retain prev_m prev_y new_date;&lt;BR /&gt;
&lt;BR /&gt;
act_m=month(date);&lt;BR /&gt;
act_y=year(date);&lt;BR /&gt;
&lt;BR /&gt;
if act_m=prev_m and act_y=prev_y then do;&lt;BR /&gt;
tot_am+amount;&lt;BR /&gt;
tot_nb+number;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
else do ;&lt;BR /&gt;
     ac=_N_-1;&lt;BR /&gt;
     if ac gt 0 then do;&lt;BR /&gt;
     set in(drop=_all_) point=ac;&lt;BR /&gt;
     output;&lt;BR /&gt;
     end;&lt;BR /&gt;
tot_am=amount;&lt;BR /&gt;
tot_nb=number;&lt;BR /&gt;
new_date=date;&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
prev_m=month(date);&lt;BR /&gt;
prev_y=year(date);&lt;BR /&gt;
&lt;BR /&gt;
if z then output;&lt;BR /&gt;
&lt;BR /&gt;
keep new_date tot_am tot_nb;&lt;BR /&gt;
&lt;BR /&gt;
format new_date date7.;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Thu, 06 Jan 2011 08:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-cummulative-overview-in-1-step-in-stead-of-several-steps/m-p/57931#M16165</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-06T08:17:04Z</dc:date>
    </item>
  </channel>
</rss>

