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

There is a table for employee data that looks like

EMPID month salary

1 jan 10

1 Feb 20

1 mar 25

2 Jan 23

2 Feb 43

2 Mar 12

3 Jan 15

3 Feb 23

3 Mar 22

 

I want a table that displays only employee id and total salary earned by them across months.

 

resultant table should look something like

1 55

2 78

3 60.

 

 

Please help me as I am very new to SAS programming and still a newbie.

 

 

Thanks a lot

1 ACCEPTED SOLUTION

Accepted Solutions
qoit
Pyrite | Level 9

A very simple SQL procedure should efficiently fix it:

 

data have;
	input empid $ month $3. salary;
	datalines;
1 jan 10
1 Feb 20
1 mar 25
2 Jan 23
2 Feb 43
2 Mar 12
3 Jan 15
3 Feb 23
3 Mar 22
;
run;

proc sql;
	create table want as
		select empid, sum(salary) as salary format=dollar10.2
			from have
				group by empid;
quit;

View solution in original post

3 REPLIES 3
qoit
Pyrite | Level 9

A very simple SQL procedure should efficiently fix it:

 

data have;
	input empid $ month $3. salary;
	datalines;
1 jan 10
1 Feb 20
1 mar 25
2 Jan 23
2 Feb 43
2 Mar 12
3 Jan 15
3 Feb 23
3 Mar 22
;
run;

proc sql;
	create table want as
		select empid, sum(salary) as salary format=dollar10.2
			from have
				group by empid;
quit;
japelin
Rhodochrosite | Level 12

try this.

data have;
input EMPID month $ salary;
datalines;
1 jan 10
1 Feb 20
1 mar 25
2 Jan 23
2 Feb 43
2 Mar 12
3 Jan 15
3 Feb 23
3 Mar 22
;
run;

data want(keep=EMPID sum);
  set have;
  by empid;
  if first.empid then sum=0;
  sum+salary;
  if last.empid;
run;

 

check

SUM Statement 

IF Statement: Subsetting 

First. and Last. Variables 

PeterClemmensen
Tourmaline | Level 20

First question: When you say "display a table", do you want a SAS data set or a report?

 

Both can be accomplished by Proc Summary.

 

proc summary data = have nway;
   class empid;
   var salary;
   output out = want(drop = _:) sum =;
run;

 

Result:

 

empid salary 
1     55 
2     78 
3     60 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 2221 views
  • 4 likes
  • 4 in conversation