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