What would be the correct code for missing values for ?
data results;
set "/home/u44696116/TheCut/input/input44.sas7bdat";
length chol_status $ 15;
drop bp_status weight_status smoking_status;
if cholesterol=. then chol_status=. ;
if cholesterol<200 then chol_status="Safe";
else if cholesterol<=239 then chol_status="High-Borderline";
else if cholesterol>=240 then chol_status="High";
run;
SAS ANSWER
data out;
set "/home/u44696116/TheCut/input/input44.sas7bdat";
length chol_status $ 15;
drop bp_status weight_status smoking_status;
if cholesterol ne . then do;
if cholesterol < 200 then chol_status='Safe';
else if cholesterol <=239 then chol_status='High-Borderline';
else if cholesterol >=240 then chol_status='High';
end;
run;
If the first place you reference the variable is when you are assigning it a numeric value then the variable will defined as numeric. So define the variable BEFORE using it.
length chol_status $20;
Also you told it to set the missing value to Safe with this statement:
if cholesterol<200 then chol_status="Safe";
SAS will consider any of the 28 missing values that SAS supports as less than any valid value.
You probably meant to have another ELSE.
if missing(cholesterol) then chol_status=' ';
else if cholesterol < 200 then chol_status='Safe';
else if cholesterol <=239 then chol_status='High-Borderline';
else if cholesterol >=240 then chol_status='High';
If the first place you reference the variable is when you are assigning it a numeric value then the variable will defined as numeric. So define the variable BEFORE using it.
length chol_status $20;
Also you told it to set the missing value to Safe with this statement:
if cholesterol<200 then chol_status="Safe";
SAS will consider any of the 28 missing values that SAS supports as less than any valid value.
You probably meant to have another ELSE.
if missing(cholesterol) then chol_status=' ';
else if cholesterol < 200 then chol_status='Safe';
else if cholesterol <=239 then chol_status='High-Borderline';
else if cholesterol >=240 then chol_status='High';
Alternatively you can try the proc format as below, for this you need to create a format and then use that format to derive a new variable.
Also, use the libname to call the dataset in the set statement.
proc format;
value chol
low-<200='Safe'
200-239='High-Borderline'
240-high='High'
other=' ';
run;
libname dat "/home/u44696116/TheCut/input";
data out;
length chol_status $ 15;
set dat.input44;
drop bp_status weight_status smoking_status;
chol_status=put(cholesterol,chol.);
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.