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 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 1566 views
  • 4 likes
  • 4 in conversation