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 |
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
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.