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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
jonna28pr0
Fluorite | Level 6

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.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
novinosrin
Tourmaline | Level 20

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;
AKHILA
Obsidian | Level 7
Thanks

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1213 views
  • 0 likes
  • 4 in conversation