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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.