BookmarkSubscribeRSS Feed
Manish_Choubey
Calcite | Level 5
Id age salary
1 23 3000
2 34 5000
4 26 2000
4 26 2000
5 32 4000
5 32 5000

Output:
Id age salary
1 23 3000
2 34 5000
4 26 4000
5 32 9000

How can we achieve this output. Plz help
2 REPLIES 2
stat_sas
Ammonite | Level 13

data have;

input id age salary;

datalines;

1 23 3000
2 34 5000
4 26 2000
4 26 2000
5 32 4000
5 32 5000

;

 

proc sql;

select id,age,sum(salary) as salary

from have

group by id,age;

quit;

EH
Obsidian | Level 7 EH
Obsidian | Level 7

Or using my favorite proc:

 

proc means data=have nway noprint;
class ID;
id age;
var salary;
output out=want (drop=_:) sum=;
run;

 

The id statement copies the age variable to the output dataset (assuming that it is constant within the variable ID).

The nway option hides the total row (all IDs).

The drop= dataset option drops the automatic variables _FREQ_ and _TYPE_.

 

Hope this helps,

Eric

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 785 views
  • 0 likes
  • 3 in conversation