how can i count the total within the subgroup?
that is for the given data the variables are id ,month ,recruitment.
A 1 4
A 2 2
A 3 3
A 4 6
A 5 3
B 1 1
B 2 2
B 3 4
B 4 5
B 5 4
C 1 1
C 2 3
C 4 2
C 5 1
D 1 2
D 2 3
D 3 2
D 4 1
D 5 4
i want to calculate the recruitment of individual ids,
desired output;
id total recruitment
A 18
B 16
C 7
D 12
please help.
data have ;
input id $ month recruitment;
cards;
A 1 4
A 2 2
A 3 3
A 4 6
A 5 3
B 1 1
B 2 2
B 3 4
B 4 5
B 5 4
C 1 1
C 2 3
C 4 2
C 5 1
D 1 2
D 2 3
D 3 2
D 4 1
D 5 4
;
proc sql;
create table want as
select id, sum(recruitment) as total_recruitment
from have
group by id;
quit;
Hi,
Please try below code.
proc means data=your_data sum;
class id;
var recruitment;
run;
I found referred the solutions from the link https://communities.sas.com/t5/SAS-Procedures/sums-and-counts-by-group/td-p/49055.
Look at any of the simple stats procs with a by group, e.g. means, summary, tabulate:
proc means data=have; by id; var recruitment; output out=want sum=sum; run;
data have ;
input id $ month recruitment;
cards;
A 1 4
A 2 2
A 3 3
A 4 6
A 5 3
B 1 1
B 2 2
B 3 4
B 4 5
B 5 4
C 1 1
C 2 3
C 4 2
C 5 1
D 1 2
D 2 3
D 3 2
D 4 1
D 5 4
;
proc sql;
create table want as
select id, sum(recruitment) as total_recruitment
from have
group by id;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.