I don't want to try Proc Sql;
I am trying to get the aggregated total for the new column.
data test.id;
set test.data;
Total_amt=sum(d_amt);
drop d_amt;
run;
Current Output Actual Output
Acct Total amt Acct Total amt
23 400 23 1000
23 600
data have;
input Acct amt;
cards;
23 400
23 600
;
run;
data want;
do until(last.Acct);
set have;
by Acct;
total_amt = sum(total_amt,amt);
end;
output;
drop amt;
run;
PROC MEANS or PROC SUMMARY will find the totals for you.
Use the CLASS statement if you want to get totals by ACCT.
I dont want to try it in Proc means or Proc Summary.... Trying to build a new data set ..so I need to do it in data step.
you could use output =dataset in proc means or summary as suggested @PaigeMiller. Please check the below paper for reference.
http://www2.sas.com/proceedings/sugi27/p018-27.pdf
@Kalai2008 wrote:
I dont want to try it in Proc means or Proc Summary.... Trying to build a new data set ..so I need to do it in data step.
As stated by @kiranv_, both PROC MEANS and PROC SUMMARY produce output data sets.
data have;
input Acct amt;
cards;
23 400
23 600
;
run;
data want;
do until(last.Acct);
set have;
by Acct;
total_amt = sum(total_amt,amt);
end;
output;
drop amt;
run;
https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic
*Create summary statistics for a dataset by a 'grouping' variable and store it in a dataset;
*Generate sample fake data;
data have;
input ID feature1 feature2 feature3;
cards;
1 7.72 5.43 4.35
1 5.54 2.25 8.22
1 4.43 6.75 2.22
1 3.22 3.21 7.31
2 6.72 2.86 6.11
2 5.89 4.25 5.25
2 3.43 7.30 8.21
2 1.22 3.55 6.55
;
run;
*Create summary data;
proc means data=have noprint;
by id;
var feature1-feature3;
output out=want median= var= mean= /autoname;
run;
*Show for display;
proc print data=want;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.