分组变量创建的三种方式:
*************分组变量的创建**********;
DATA obese1;
length status $ 15;
set sashelp.class;
bmi=weight*0.4536/(height*0.0254)**2;
if bmi<18.5 then status="underweight";
else if bmi<25 then status="normal";
else if bmi<30 then status="overweight";
else status="obese";
run;
************SELECT-WHEN************;
DATA obese2;
length status $ 15;
set sashelp.class;
bmi=weight*0.4536/(height*0.0254)**2;
select ;
when (bmi<18.5) status="underweight";
when (bmi<25) status="normal";
when (bmi<30) status="overweight";
other status="obese";
end;
run;
proc sql;
create table obese3 as
select *,weight*0.4536/(height*0.0254)**2 as bmi,
case when (calculated bmi<18.5) then "underweight"
when (calculated bmi<25) then "Normal"
when (calculated bmi<30) then "Overweight"
else "obese"
end as status
from sashelp.class;
quit;