BookmarkSubscribeRSS Feed
psnorrod
Obsidian | Level 7

Hello,

New-ish SAS user here.

 

I want to count the number of events that occur by year, sex, and age_group. I have attached two data sets where "sample1" represents my data and "sample2" represents what I need for a final product.

 

Using the code below, SAS will count the number of events but is combining age groups. For example, during 2003 combines the events for age_group=3 into the count of events for age_group=3 for state=27.

 

/* count code */

proc sort data = one;
by year state;
run;

 

data two;
set one;
by year state ;
if first.state then count = 0;
count + 1;
if last.state;
keep year count Sex age_group;
run;

 

"Sample1" represents my data and "Sample2" represents the what I want in a final product.

 

Thank you!

 

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

Hi @psnorrod

 

Could you please put your sample data directly in the question as many of us won't download files due to security issues.

Thank you!

psnorrod
Obsidian | Level 7

Yes, thank you for the reminder @ed_sas_member 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 754 views
  • 0 likes
  • 2 in conversation