BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Geo-
Quartz | Level 8

how to use data step or sql to achieve this.any suggestions or ideas ?

thanks!

 

orignial data:

datespend
201808015
201808014
201808023
201808027
201808021
201808030.5

 

want:

datesumCumulative
201808019
2018080220
2018080320.5

 

logic:

datecumulativeSum
201808015+4
201808025+4+3+7+1
201808035+4+3+7+1+0.5
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
infile cards expandtabs;
input date	spend;
cards;
20180801	5	 	 	20180801	5+4
20180801	4	 	 	20180802	5+4+3+7+1
20180802	3	 	 	20180803	5+4+3+7+1+0.5
20180802	7	 	 	 	 
20180802	1	 	 	 	 
20180803	0.5
;
run;
proc summary data=have;
by date;
var spend;
output out=temp sum=;
run;
data want;
 set temp;
 sum+spend;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Please supply example data in a usable form (datastep with datalines), and show the expected output.

You can't have two columns with the same name in a dataset.

Ksharp
Super User
data have;
infile cards expandtabs;
input date	spend;
cards;
20180801	5	 	 	20180801	5+4
20180801	4	 	 	20180802	5+4+3+7+1
20180802	3	 	 	20180803	5+4+3+7+1+0.5
20180802	7	 	 	 	 
20180802	1	 	 	 	 
20180803	0.5
;
run;
proc summary data=have;
by date;
var spend;
output out=temp sum=;
run;
data want;
 set temp;
 sum+spend;
run;
novinosrin
Tourmaline | Level 20
data have;
infile cards expandtabs;
input date	spend;
cards;
20180801	5	 	 	20180801	5+4
20180801	4	 	 	20180802	5+4+3+7+1
20180802	3	 	 	20180803	5+4+3+7+1+0.5
20180802	7	 	 	 	 
20180802	1	 	 	 	 
20180803	0.5
;
run;

data want;
do until(last.date);
set have;
by date;
sum+spend;
end;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4509 views
  • 3 likes
  • 4 in conversation