BookmarkSubscribeRSS Feed
annapurna
Calcite | Level 5

my dataset has variables subject gender bmi

and a format is applied to bmi as

proc format;                                                                                                                           

value body   35-high='very obese'                                                                                                      

             30-34.9='obese'                                                                                                           

             25-29.9='over weight'                                                                                                     

             18.5-24.9='normal'                                                                                                        

             16-18.49='underweight'                                                                                                    

             low-<16='very underweight';                                                                                               

run;                                                                                                                                   

                               

i want to generate a data set with counts for bmi using

proc sql with the following code but not able to get the desired output.

proc sql;                                                                                                                              

create table case.demo_2 as                                                                                                            

select  bmi ,count(*) as total                                                                                                         

from case.demo_1                                                                                                                       

group by bmi;                                                                                                                          

quit;

however  with proc freq am able to get the required output

proc freq data=case.demo_1;                                                                                                            

tables bmi/out=case.demo_f;                                                                                                            

run;

bmi                      count

very underweight      1

underweight             2

normal                   21

over weight             6

obese                     3

very obese             1

please help me writing a code using proc sql

thanks in advance.

2 REPLIES 2
Reeza
Super User

AFAIK proc sql doesn't recognize formats when calculating.

You'll need to convert your BMI variable using the put function:

proc format;                                                                                                                          

value body   35-high='very obese'                                                                                                     

             30-34.9='obese'                                                                                                          

             25-29.9='over weight'                                                                                                    

             18.5-24.9='normal'                                                                                                       

             16-18.49='underweight'                                                                                                   

             low-<16='very underweight';                                                                                              

run; 

data have;

do BMI=10 to 40;

output;

end;

format BMI body.;

run;

proc sql;                                                                                                                             

create table want as                                                                                                           

select  put(bmi, body.) as BMI,count(*) as total                                                                                                        

from have                                                                                                                      

group by calculated bmi;                                                                                                                         

quit;

proc print data=want;

run;

jakarman
Barite | Level 11

Why not use proc tabulate / proc report  they are made and designed to do that type of work.

More interesting with an external DBMS system supporting SAS formats (need to publish those).

---->-- ja karman --<-----

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 908 views
  • 0 likes
  • 3 in conversation