I'm trying to recode age into groups but this is not working (just takes the first number in the bracket, from what I can tell)
data new;
set have;
if age in (15-24) then agegroup=1;
else if age in (25-54) then agegroup=2;
else if age >= 55 then agegroup=3;
run;
What is the proper way to do this?
Edit: Also I know one can do it the way below, but it is very tedious, especially when there are more than 3 values being made. I'm looking for something easier, with ranges:
One way is to not add any variables an use your existing data set and assign a format to the variable.
proc format;
value agegrp
1 - 24 = '1'
25 - 54= '2'
55 - high='3';
run;
proc freq data=have;
tables age;
format age agegrp.;
run;
The format will create the group for the counts as well as changing displayed value.
Your code is not correct, use the colon : to indicate a numeric range with the IN operator
if age in (15:24) then agegroup=1;
else if age in (25:54) then agegroup=2;
else if age >= 55 then agegroup=3;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.