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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

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
  • 4 replies
  • 914 views
  • 0 likes
  • 4 in conversation