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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.