I have always received an error when I use "Is Missing". For example in the code below:
data work.lowchol work.highchol work.misschol;
set sashelp.heart;
if cholesterol is missing then output work.misschol;
else if cholesterol lt 200 then output work.lowchol;
else if cholesterol ge 200 then output work.highchol;
run;
Error Message:
28 if cholesterol is missing then output work.misschol;
__
388
76
ERROR 388-185: Expecting an arithmetic operator.
ERROR 76-322: Syntax error, statement will be ignored.
Can anyone let me know why this happens? or if i am making a mistake here?
if cholesterol is missing then output work.misschol;
Use MISSING as a function like:
if missing(cholesterol) then output work.misschol;
if cholesterol is missing then output work.misschol;
Use MISSING as a function like:
if missing(cholesterol) then output work.misschol;
Thank you this removed all errors from the code.
data work.lowchol work.highchol work.misschol;
set sashelp.heart;
if missing(cholesterol) then output work.misschol;
else if cholesterol lt 200 then output work.lowchol;
else if cholesterol ge 200 then output work.highchol;
run;
Hello @primukh26
You could use WHERE to make "is missing" work like->
/*Create sample input data*/
data have;
do i=1 to 5;
do cholesterol =.,0 to 300;
output;
end;
end;
run;
/*Test where cholesterol is missing*/
data work.lowchol(where=(0<=cholesterol<= 200))
work.highchol(where=(cholesterol gt 200))
work.misschol(where=(cholesterol is missing));
set have;
run;
IS MISSING has no special meaning to SAS data step code. So the error message is telling you that you did not include any operator between the variable CHOLESTEROL and the variable IS.
You can compare variables to the missing value which is represented by a period for numeric variables or a blank for character variables.
if cholesterol = . then output work.misschol;
else if cholesterol lt 200 then output work.lowchol;
else if cholesterol ge 200 then output work.highchol;
Note that SAS also has 27 other "special" missing numeric values which are represented by ._ and .A to .Z which are distinct and different than regular missing value. So it could be safer to use the MISSING() function to test if a variable is missing or not. The MISSING() function works for both numeric and character variables.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.