how to use data step or sql to achieve this.any suggestions or ideas ?
thanks!
orignial data:
| date | spend |
| 20180801 | 5 |
| 20180801 | 4 |
| 20180802 | 3 |
| 20180802 | 7 |
| 20180802 | 1 |
| 20180803 | 0.5 |
want:
| date | sumCumulative |
| 20180801 | 9 |
| 20180802 | 20 |
| 20180803 | 20.5 |
logic:
| date | cumulativeSum |
| 20180801 | 5+4 |
| 20180802 | 5+4+3+7+1 |
| 20180803 | 5+4+3+7+1+0.5 |
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;
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.
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.