BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kalai2008
Pyrite | Level 9

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
SAS_inquisitive
Lapis Lazuli | Level 10
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;

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

PROC MEANS or PROC SUMMARY will find the totals for you.

 

Use the CLASS statement if you want to get totals by ACCT.

--
Paige Miller
Kalai2008
Pyrite | Level 9

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.

kiranv_
Rhodochrosite | Level 12

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

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Kalai2008
Pyrite | Level 9
Thank you I will try it.
SAS_inquisitive
Lapis Lazuli | Level 10
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;
Kalai2008
Pyrite | Level 9
Thank you!..It worked!
Reeza
Super User

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;
Kalai2008
Pyrite | Level 9
Thank you..It worked

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
  • 9 replies
  • 2076 views
  • 0 likes
  • 5 in conversation