I have a dataset that looks like:
qy balance
2010 Q1 50
2010 Q2 100
2010 Q3 200
and I would like to create a new column which contains the total sum i.e. desired output:
qy balance total_balance
2010 Q1 50 1000
2010 Q2 100 1000
2010 Q3 200 1000
How can I do that?
Hi @adrfinance
Same logic as previously. You just need to remove the 'group by qy' clause:
data have; input qy $ 1-8 balance; datalines; 2010 Q1 50 2010 Q1 50 2010 Q2 100 2010 Q2 100 2010 Q2 100 2010 Q3 200 2010 Q3 200 2010 Q3 200 ; run; proc sql; create table want as select qy, balance, sum(balance) as sum_balance from have; quit;
Best,
View solution in original post
In the data step approach..
data want; do until (lr1); set have end=lr1; sum_balance + balance; end; do until (lr2); set have end=lr2; output; end; run;
you have a typo in your code with the "haveend" or not?
Indeed 🙂 Good catch
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
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.