BookmarkSubscribeRSS Feed
bncoxuk
Obsidian | Level 7
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;
6 REPLIES 6
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
bncoxuk
Obsidian | Level 7
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;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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
bncoxuk
Obsidian | Level 7
Thanks SPR.

But can I know why the 'WHERE sex is missing' works?, but 'IF sex is missing' is wrong?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1938 views
  • 0 likes
  • 3 in conversation