BookmarkSubscribeRSS Feed
Novice_
Fluorite | Level 6

Hi,

 

Is there an easy way of creating 5-year age groups from a numeric age variable?

I need 0-4, 5-9, 10-14, 15-19, 20-24, 25-29, 30-34, 35-39, 40-44 ..............75-79 and 80+

Thanks

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Yes. Create a custom format and use that in a Format Statement in Proc Means / Proc Summary or whatever procedure you're using.

Rick_SAS
SAS Super FREQ

The easiest way is to define the ranges by using PROC FORMAT as shown in this article:

"Use SAS formats to bin numerical variables."

 

You then apply the format by using a FORMAT statement in a procedure or DATA step. For example:

proc format;
value AgeFmt  
      low -<  5  = "0-4"
        5 -<  10 = "5-9"
       10 -<  15 = "10-14" 
       15 -<  20 = "15-20"
       /* and so forth */
       80 -   high  = "80+"; 
run;

proc freq data=sashelp.class;
   format age AgeFmt.;
   tables age;
run;
ballardw
Super User

Formats as suggested by @Rick_SAS and @PeterClemmensen are an extremely powerful tool in SAS.

 

One of the advantages is suppose after you do an analysis with the proposed 5-year age groups you are asked about minor changes such as 0 to 12, 13-18, 19-25 and 26 and older with the 5 year groups. Just create a new format, which takes about 2 minutes and use the new format in the same analysis. The groups created by formats will be honored by almost every analysis, reporting and graphing procedure in SAS. You can also make one of your custom formats the default for the most common tasks but the custom formats are available for custom tasks. I have something like a dozen frequent to occasional use formats for age such as 3-year, 5-year, 10-year intervals plus specific age groups for topics related to specific medical testing recommended ages or key age groups for funding.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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