Help using Base SAS procedures

Be careful with missing values

Reply
Occasional Contributor
Posts: 13

Be careful with missing values

The numeric value for a is 18735.

data work.test;
a='18APR11'D;
b=.;
output;
run;

data work.test2;
set work.test;
if a-b>1825 then c=1;
if a-b<1825 then c=2;
run;

proc print data=work.test2;
run;

Result: c=2.

Why c=2? It makes more sense if it is 1.
Respected Advisor
Posts: 2,655

Re: Be careful with missing values

Posted in reply to Kevin_Graduate
The value for a-b is ., which is less than any value. I would expect c=2 as the only possible result.

Steve Denham
Trusted Advisor
Posts: 1,321

Re: Be careful with missing values

Posted in reply to Kevin_Graduate
Hi Kevin,

If you want missing values to be ignored use SAS functions instead...

e.g.
if sum(a,-b)>1825 then c=1;
if sum(a,-b)<1825 then c=2;

this will then ignore the missing value and you will get your desired c=1 as your result.

This is described in the SAS documentation and in the SAS programming 1 course.

Kind Regards,
Michelle
Ask a Question
Discussion stats
  • 2 replies
  • 130 views
  • 0 likes
  • 3 in conversation