BookmarkSubscribeRSS Feed
Baraso
Fluorite | Level 6

Hi everyone,

I explain what I want to do using the simplified table below. I would like to total the number of patients for each age group across all sites for each category of region. Taking table B from table A as an example. Any guidance on how to do it would be greatly appreciated. Thank you.

A

 

A:   
SiteIDAge_groupRegion Num_Patients
Site0118_25NA500
Site0118_25MW703
Site0118_25Miss500
Site0118_25NE507
Site0118_25Other500
Site0118_25S1239
Site0118_25W541
Site0126_44NA502
Site0126_44MW1087
Site0126_44Miss500
Site0126_44NE604
Site0126_44Other500
Site0126_44S2763
Site0126_44W685
Site0218_25NA533
Site0218_25MW4278
Site0218_25Miss500
Site0218_25NE1964
Site0218_25Other500
Site0218_25S7340
Site0218_25W3242
Site0226_44NA566
Site0226_44MW5920
Site0226_44Miss500
Site0226_44NE2512
Site0226_44Other501
Site0226_44S11502
Site0226_44W5065

 

B

B:   
SiteIDAge_groupRegion Num_Patients
ALL18_25NA1033
ALL18_25MW4981
ALL18_25Miss1000
ALL18_25NE2471
ALL18_25Other1000
ALL18_25S8579
ALL18_25W3783
ALL26_44NA1068
ALL26_44MW7007
ALL26_44Miss1000
ALL26_44NE3116
ALL26_44Other1001
ALL26_44S14265
ALL26_44W5750
3 REPLIES 3
Mazi
Pyrite | Level 9
data have;
	infile datalines dlm=',';
	input SiteID $ Age_group $ Region $ Num_Patients;
datalines;
Site01,18_25,NA,500
Site01,18_25,MW,703
Site01,18_25,Miss,500
Site01,18_25,NE,507
Site01,18_25,Other,500
Site01,18_25,S,1239
Site01,18_25,W,541
Site01,26_44,NA,502
Site01,26_44,MW,1087
Site01,26_44,Miss,500
Site01,26_44,NE,604
Site01,26_44,Other,500
Site01,26_44,S,2763
Site01,26_44,W,685
Site02,18_25,NA,533
Site02,18_25,MW,4278
Site02,18_25,Miss,500
Site02,18_25,NE,1964
Site02,18_25,Other,500
Site02,18_25,S,7340
Site02,18_25,W,3242
Site02,26_44,NA,566
Site02,26_44,MW,5920
Site02,26_44,Miss,500
Site02,26_44,NE,2512
Site02,26_44,Other,501
Site02,26_44,S,11502
Site02,26_44,W,5065
;
run;

proc sql;
	create table want as
		select "ALL" as siteid
			  ,age_group
			  ,region
			  ,sum(Num_Patients) as Num_Patients
	from have
	group by age_group,region
	order by age_group;
quit;

Can you try this?

Tom
Super User Tom
Super User

Try PROC SUMMARY,  PROC FREQ,  PROC REPORT and PROC TABULATE. All of those should be able to make this report.

ballardw
Super User

An example of a report with the desired elements though different appearance using Proc Tabulate:

proc tabulate data=have out=tabout;
   class  SiteID  Age_group  Region ;
   var Num_Patients;
   table (All='All Sites' SiteId)*age_group*region,
         Num_patients*sum=''
   ;
run;

Tabulate doesn't repeat row or column heading that are groups of related values.

The ALL instruction is the way to get a group total across other values of the variable. I tend to use something a bit more than just "All" for labels so I can tell all of what...

Note that proc tabulate can produce multiple tables in one procedure call such as:

proc tabulate data=have ;
   class  SiteID  Age_group  Region ;
   var Num_Patients;
   table (All='All Sites' SiteId)*age_group*region,
         Num_patients*sum=''
   ;
   table (All='All Ages' age_group )*SiteId*region,
         Num_patients*sum=''
   ;
run;

which is one reason I'm a bit more verbose with the ALL label.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 595 views
  • 4 likes
  • 4 in conversation