I am trying to regroup the age variable into a new variable called Age_Group. I keep getting errors when I try to run. Here is how I added a new variable:
data work.new;
set work.working_set;
Age_Group=Age;
run;
And here is the code that I am trying to run.
data work.new1;
set new_data;
if Age_Group LE 29 then Age_Group='18-29';
if Age_Group GE 30 AND LE 39 then Age_Group='30-39';
if Age_Group GE 40 AND LE 49 then Age_Group='40-49';
if Age_Group GE 50 AND LE 59 then Age_Group='50-59';
if Age_Group GE 60 AND LE 69 then Age_Group='60-69';
if Age_Group GE 70 AND LE 79 then Age_Group='70-79';
if Age_Group GE 80 then Age_Group='80+';
run;
Can anyone help or give suggestions? Thank you!
proc format;
value agef low-29='18-29' 30-39='30-39' /* you type the rest */ ;
run;
data new1;
set new;
format age agef.;
run;
There is also inconsistency in the data sets referenced.
First data step:
input data set: working_set
output data set: new
Second data step:
input data set: new_data (not shown, or typo? No relation to previous step)
output data set: new1
data work.new;
set working_set;
if age LE 29 AND not missing(age) then Age_Group='18-29';
else if age GE 30 AND age LE 39 then Age_Group='30-39';
*simpler way to write the else if;
*else if 30<=age <=39 then Age_Group='30-39';*
else if age GE 40 AND age LE 49 then Age_Group='40-49';
else if age GE 50 AND age LE 59 then Age_Group='50-59';
else if age GE 60 AND age LE 69 then Age_Group='60-69';
else if age GE 70 AND age LE 79 then Age_Group='70-79';
else if age GE 80 then Age_Group='80+';
run;
@madisonahrens wrote:
I am trying to regroup the age variable into a new variable called Age_Group. I keep getting errors when I try to run. Here is how I added a new variable:
data work.new;
set work.working_set;
Age_Group=Age;
run;
And here is the code that I am trying to run.
data work.new1;
set new_data;
if Age_Group LE 29 then Age_Group='18-29';
if Age_Group GE 30 AND LE 39 then Age_Group='30-39';
if Age_Group GE 40 AND LE 49 then Age_Group='40-49';
if Age_Group GE 50 AND LE 59 then Age_Group='50-59';
if Age_Group GE 60 AND LE 69 then Age_Group='60-69';
if Age_Group GE 70 AND LE 79 then Age_Group='70-79';
if Age_Group GE 80 then Age_Group='80+';
run;
Can anyone help or give suggestions? Thank you!
proc format;
value agef low-29='18-29' 30-39='30-39' /* you type the rest */ ;
run;
data new1;
set new;
format age agef.;
run;
That worked! Thank you so much @PaigeMiller
Why are you categorizing a perfectly good continuous variable? From a statistical point of view, it is the equivalent of taking a Lamborghini into the shop and asking them to cut it up into pieces that might fit into the garage better. See this link:https://discourse.datamethods.org/t/categorizing-continuous-variables/3402
SteveDenham
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.