data out;
set INPUT.input44;
drop bp_status weight_status smoking_status;
if cholesterol lt 200 then
do;
chol="SAFE";
output safe;
end;
Else if cholesterol le 239 then
do;
chol="HIGH_BORDRLINE";
output high_bord;
end;
else if cholesterol ge 240 then
do;
chol="HIGH";
output high;
end;
where cholesterol is not missing;
RUN;
Log Section:
please let me know in simple way where i am lacking as I am new to SAS and learning it .
If you use an OUTPUT statement with a data set name to write to then you need this output data set also in your DATA statement.
data SAFE HIGH_BORD HIGH; ..... output safe; ..... output high_bord; ..... output high; ..... run;
Looking at your code I feel that it might be better to just populate a variable and write all the data to a single table.
data out;
set INPUT.input44;
drop bp_status weight_status smoking_status;
length chol $14;
if cholesterol lt 200 then
do;
chol="SAFE";
end;
else if cholesterol le 239 then
do;
chol="HIGH_BORDRLINE";
end;
else if cholesterol ge 240 then
do;
chol="HIGH";
end;
where cholesterol is not missing;
RUN;
One neat and easy to maintain option for recoding values is the use of a format.
proc format;
value chol_group
low-<200 = 'SAFE'
200-<240 = 'HIGH_BORDRLINE'
240-high = 'HIGH'
other = 'not defined'
;
run;
data out;
set INPUT.input44;
where cholesterol is not missing;
drop bp_status weight_status smoking_status;
chol=put(cholesterol,chol_group.);
RUN;
You cannot output to a dataset that you did not tell SAS the data step was going to create. If you want to write to three different datasets then you must list all of them in the DATA statement, just as the message says.
Also do not put the WHERE statement so far away from the SET statement that it applies to. You will just confuse yourself.
data safe high_bord high;
set INPUT.input44;
where cholesterol is not missing;
If you use an OUTPUT statement with a data set name to write to then you need this output data set also in your DATA statement.
data SAFE HIGH_BORD HIGH; ..... output safe; ..... output high_bord; ..... output high; ..... run;
Looking at your code I feel that it might be better to just populate a variable and write all the data to a single table.
data out;
set INPUT.input44;
drop bp_status weight_status smoking_status;
length chol $14;
if cholesterol lt 200 then
do;
chol="SAFE";
end;
else if cholesterol le 239 then
do;
chol="HIGH_BORDRLINE";
end;
else if cholesterol ge 240 then
do;
chol="HIGH";
end;
where cholesterol is not missing;
RUN;
One neat and easy to maintain option for recoding values is the use of a format.
proc format;
value chol_group
low-<200 = 'SAFE'
200-<240 = 'HIGH_BORDRLINE'
240-high = 'HIGH'
other = 'not defined'
;
run;
data out;
set INPUT.input44;
where cholesterol is not missing;
drop bp_status weight_status smoking_status;
chol=put(cholesterol,chol_group.);
RUN;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.