- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes. Create a custom format and use that in a Format Statement in Proc Means / Proc Summary or whatever procedure you're using.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.