BookmarkSubscribeRSS Feed
SannaSanna
Quartz | Level 8

Hello everyone! 

 

This Forum is just the best for help and hints! 

 

I am trying to produce counts and I am having difficulty trying to figure out the logic to code this scenario.  I am trying to count individuals by their age as well as produce counts in their age groupings.  I am essentially counting each individual twice (once at their actual age and then again in an age grouping category)  My SAS code seem to capture the record once and I cannot figure out a way to count the record twice.  Any help or advice would be greatly appreciated.  I have included sample data and a results table in which I would like to see the counts.  The results table under the Age column will reflect the age of (ID) as well as counted again in the age grouping.  For example, ID=SJ990 is counted once under age (12) and then again under age (10-15) under the Count column.  Can anyone assist me with figuring out how I can achieve this?  Thank you in advance! 

  

Sample Data Table  
ID age location
SJ990 12 R119
MR213 17 R119
SS913 17 B099
AT893 11 B099
TL332 22 B099
     
Results Table  
Age Count  
11 1  
12 1  
17 2  
22 1  
10-15 2  
16-22 3  
3 REPLIES 3
Reeza
Super User

SAS supports this using Multilabel Formats.

 

Rough idea:

proc format;
value age_mlf_fmt (multilabel)
10 = 10
11 = 11
12 = 12
13 = 13 
....
10-15 = '10 - 15'
16-22 = '16 - 22';
run;

proc tabulate data=have;
class age / mlf;
format age age_mlf_fmt.;
table age;
run;

Tested fully worked exmaple:

https://gist.github.com/statgeek/1c6f38ef368a4272cf458b017fc63d4b

 


@SannaSanna wrote:

Hello everyone! 

 

This Forum is just the best for help and hints! 

 

I am trying to produce counts and I am having difficulty trying to figure out the logic to code this scenario.  I am trying to count individuals by their age as well as produce counts in their age groupings.  I am essentially counting each individual twice (once at their actual age and then again in an age grouping category)  My SAS code seem to capture the record once and I cannot figure out a way to count the record twice.  Any help or advice would be greatly appreciated.  I have included sample data and a results table in which I would like to see the counts.  The results table under the Age column will reflect the age of (ID) as well as counted again in the age grouping.  For example, ID=SJ990 is counted once under age (12) and then again under age (10-15) under the Count column.  Can anyone assist me with figuring out how I can achieve this?  Thank you in advance! 

  

Sample Data Table  
ID age location
SJ990 12 R119
MR213 17 R119
SS913 17 B099
AT893 11 B099
TL332 22 B099
     
Results Table  
Age Count  
11 1  
12 1  
17 2  
22 1  
10-15 2  
16-22 3  

 

 

SannaSanna
Quartz | Level 8
Thank you Reeza! Is there a way I can use the aggregated count record rows for further processing? I would like to run further cross tabulations on and want to use the column 'Age' with the aggregated groupings (meaning counting the individuals age as well as counting them again in the aggregated form) to get further results?
Reeza
Super User
I'm not sure what you mean by the second question, but you can use PROC MEANS or TABULATE and save the output to a data set instead of having it displayed if that's what you're asking about. Use the OUT= option on PROC TABULATE or there are a variety of options with PROC MEANS.

proc tabulate data=have out=AGG_SUMMARY;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 770 views
  • 1 like
  • 2 in conversation