data newclass; set sashelp.class; length Patient $12.;
If weight <=84 then Patient= 'UnderWeight '; else
If weight >84 and weight <=100 then Patient= 'ProperWeight '; else
If weight >100 then Patient= 'OverWeight '; else
Patient= 'OutLier '; run;
======================================================================
SELECT WHEN END statement can also be use in place of IF THEN ELSE statement.
LENGTH is to be use so that the new coloum create (Patient) will have defined length that is $12.
data newclass; set sashelp.class (keep= name weight); Length Grade $12.;
Select;
when (weight <=84) Grade= 'Lower '; when (weight >84 and weight <=100) Grade= 'Medium '; when (weight >100) Grade = 'Highest '; otherwise Grade = 'NA '; end;
-------------------------------------------------
run;
data Cars_New; set sashelp.cars (keep= Make MSRP);
Length sales $14.; select; when (MSRP <=10500) sales= 'Lowest '; when (MSRP > 10500 and MSRP <= 18000) sales= 'Medium '; when (MSRP > 18000) sales = 'Heighest '; otherwise sales= 'outlier ';
End;
run;
===================================================================================
To create more then one dataset from one dataset
data Cars_SUV Cars_SEDAN Cars_OTHERS; set sashelp.cars ;
If Type = 'SUV ' then output Cars_SUV; else
If Type = 'Sedan ' then output Cars_SEDAN; else output Cars_OTHERS;
RUN;
RETAIN Statement: It initialize a value to a variable Do Loops; Leave Data detail; do var= 1 to 10; if var=7 then leave; (Leave will tel progm to stop when reach Var=7) else; output; end; run; Do Loops; continue Data detail;
Do var= 1 to 15; if var= 8 then continue; (Continue will tel program to continue when Var=7) else; output; end; run;
Do Until: until