BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tatiana1
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
paulkaefer
Lapis Lazuli | Level 10
Great question! Do you want separate data sets for each group?
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.

Another solution is a user-defined format. There's a good tutorial here if you'd prefer that.

View solution in original post

4 REPLIES 4
paulkaefer
Lapis Lazuli | Level 10
Great question! Do you want separate data sets for each group?
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.

Another solution is a user-defined format. There's a good tutorial here if you'd prefer that.
Tatiana1
Calcite | Level 5

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;

paulkaefer
Lapis Lazuli | Level 10

Well if you do it like that, lowIMC, mediumIMC, highIMC, and error are different data sets. So use a separate PROC MEANS for each.

ballardw
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1344 views
  • 0 likes
  • 3 in conversation