I am with SAS studio.
I have a sas7data file with a large table with different subjects as the independant variable and their anthropometric data (weight, age, BMI, etc) as dependant variables.
I am trying to sort this data by BMI (for body mass index) in order to creat groups of people having a BMI < or = to 25, >25 to <30 and > or = 30. How do I do this?
Thank you!
data lowBMI mediumBMI highBMI error;
set originalDataSet;
select;
when (BMI <= 25) output lowBMI;
when (BMI < 30) output mediumBMI;
when (BMI >= 30) output highBMI;
otherwise output error;
end;
run;If you want to keep them in the same data set but add a variable with category, you can instead of "output dataSet" say BMIcategory = "low", for example.data lowBMI mediumBMI highBMI error;
set originalDataSet;
select;
when (BMI <= 25) output lowBMI;
when (BMI < 30) output mediumBMI;
when (BMI >= 30) output highBMI;
otherwise output error;
end;
run;If you want to keep them in the same data set but add a variable with category, you can instead of "output dataSet" say BMIcategory = "low", for example.Thank you sooo much,
now I need to analyze the means of different variables of these groups. This following procedure says that this "proc means; by lowIMC mediumIMC highIMC error" are not valid groups.... what should I do....
data lowIMC mediumIMC highIMC error;
set BIOMRKR;
select;
when (IMC <= 25) output lowIMC;
when (IMC < 30) output mediumIMC;
when (IMC >= 30) output highIMC;
otherwise output error;
end;
run;
proc means; by lowIMC mediumIMC highIMC error; var fruit legume f_l dietacar dietbcar bcryp lycopene lutzea;run;
proc corr;var fruit dietacar; run;
proc corr; var fruit dietbcar;run;
Well if you do it like that, lowIMC, mediumIMC, highIMC, and error are different data sets. So use a separate PROC MEANS for each.
It may be much easier in the long run to use Paulkaefer's idea of adding a variable to represent the categories.
Please see:
data want;
set originalDataSet;
select;
when (BMI <= 25) BmiCat='Low';
when (BMI < 30) BmiCat='Medium';
when (BMI >= 30) BmiCat='Obese';
otherwise ;
end;
run;
proc means data=want;
class BmiCat;
var fruit legume f_l dietacar dietbcar bcryp lycopene lutzea;
run;
proc sort data=want;
by BmiCat;
run;
proc corr data=want;
by BmiCat;
var Fruit dietacar;
run;
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!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.