Conditional Programming
Conditional Programming
Using the SASHELP data set FISH, create a new, temporary SAS data set
called Group_Fish that contains variables Species, Weight, and Height. Using IF-
THEN-ELSE logic, create a new variable called Group_Fish that places the fish into
weight as follows.
O to 100=1, 101-200=2, 201-500=3, 501-1000=4 and 1001 and greater-5
Use PROC_PRINT to list the first 10 observations from the data set Group_Fish
and show it in class.
Q2. Create a new temporary SAS data set called High_BP containing subjects
from SASHELP.Heart data set who have systolic blood pressure greater than 250
or diastolic blood pressure greater than 180. The new data set should only have
variables Diastolic, Systolic, and Status.
Use PROC_PRINT to list the contexts of High_BP.
Ans 1
/* Step 1: Create the temporary dataset Group_Fish with specified variables and
logic */
data Group_Fish;
set sashelp.fish; /* Access the SASHELP.FISH dataset */
/* Retain only the required variables */
keep Species Weight Height Group_Fish;
/* Use IF-THEN-ELSE logic to classify weights into groups */
if Weight <= 100 then Group_Fish = 1;
else if Weight <= 200 then Group_Fish = 2;
else if Weight <= 500 then Group_Fish = 3;
else if Weight <= 1000 then Group_Fish = 4;
else Group_Fish = 5;
run;