Hi All,
I'm wanting to categorise a continuous variable into groups based on criteria set from values in other variables.
Briefly, I have Body Mass Index data (BMI) for individuals identified by sex and age (e.g. Female, 14; Male, 17). I've got percentile data of the BMI for each sex and age combination (e.g. 5th percentile, 85th percentile, 95th percentile), which has been merged with the BMI data. I'm wanting to create a new variable (named 'BMI_category') that categorises each individual into a weight range class (Underweight, Healthy, Overweight, and Obese) based on BMI percentile data. The first few lines of the dataset are shown in the image attached:
So for the first individual in the example dataset, they would be classified based on their BMI (21.2) as being 'Healthy' because their BMI is between the 5th percentile (15.5) and the 85th percentile (23.3).
So far I've used the following code to categorise each individual:
proc format;
value f_BMI_category
0 = 'Underweight'
1 = 'Healthy'
2 = 'Overweight'
3 = 'Obese';
run;
data BMImerged3;
set BMImerged2;
where Sex = 'Female' and Age = 14;
if BMI <15.5 then BMI_category = 0;
if BMI >=15.5 and BMI <23.3 then BMI_category = 1;
if BMI >=23.3 and BMI <27.1 then BMI_category = 2;
if BMI >=27.1 then BMI_category = 3;
format BMI_category f_BMI_category.;
run;
This code above works fine for the BMI percentile data for Females aged 14 years, because I have set the categorisation manually for the BMI ranges for each category (e.g. <15.5, >=15.5, >23.3 etc). To speed up the process, how can I set the thresholds for categorisation for one variable (e.g. BMI) based on values from other variables in the same dataset (e.g. _5th percentile values)?
Thanks in advance.
Please see this link: https://www.cdc.gov/nccdphp/dnpao/growthcharts/resources/sas.htm
For code and rational of BMI for age percentile assignments.
Then assign the category based on the actual BMI percentile. Your age range is a tad "wide" for precision. I hope you have date of birth and date of measurement to get a matching interval from the CDC charts.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.