Help using Base SAS procedures

IS MISSING caused 0 observations

Reply
Frequent Contributor
Posts: 131

IS MISSING caused 0 observations

Hi folks,

I used DATA step to manipulate data. The first method lead to 0 observations, while the second one works fine. Why in this case the 'IS MISSING' statement is wrong?

DATA work.driver;
SET user.driver;
IF sex='X' or sex is missing THEN sex='M';
RUN;


DATA work.driver;
SET user.driver;
IF sex='X' or MISSING(sex) THEN sex='M';
RUN;
Super Contributor
Super Contributor
Posts: 365

Re: IS MISSING caused 0 observations

Hello Bncoxuk,

There is an error in your IF statement. Correct version is like this:
[pre]
IF sex='X' or sex ='' THEN sex='M';
[/pre]
Sincerely,
SPR
Frequent Contributor
Posts: 131

Re: IS MISSING caused 0 observations

Can you please tell why the addition of an option causes the problem? So the 2nd one is wrong, as compared to the 1st one.

DATA work.driver;
SET user.driver;
IF sex is missing;
RUN;

DATA work.driver;
SET user.driver;
IF sex='X' or sex is missing;
RUN;
Super Contributor
Super Contributor
Posts: 3,174

Re: IS MISSING caused 0 observations

In the SASLOG, I expect you also got these messages with the illegal syntax, so SAS stopped processing and you will get no observations:


ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

7 RUN;

NOTE: The SAS System stopped processing this step because of errors.


Scott Barry
SBBWorks, Inc.
Super Contributor
Super Contributor
Posts: 365

Re: IS MISSING caused 0 observations

Both of these examples are erroneous. It is not such syntax like "sex is missing". SAS generates the following error:
[pre]
23 IF sex is missing;
__
388
76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.
[/pre]
HTH
SPR
Frequent Contributor
Posts: 131

Re: IS MISSING caused 0 observations

Thanks SPR.

But can I know why the 'WHERE sex is missing' works?, but 'IF sex is missing' is wrong?
Super Contributor
Super Contributor
Posts: 3,174

Re: IS MISSING caused 0 observations

Basically, the WHERE statement syntax is different than the IF statement syntax - see DOC link.

Syntax of WHERE Expression
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000999255.htm

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 6 replies
  • 208 views
  • 0 likes
  • 3 in conversation