DATA Step, Macro, Functions and more

IF else cond not working

Occasional Contributor
Posts: 7

IF else cond not working

Hello Everyone!!

For the below dataset, I want to find the record where name is not null and gender is null.  Why if condition is not working .

data x;

input id name $ gender $;


101 rakesh kumar

102 . goyal

103 namita .



data test1;

set x;

if name ne '' and gender eq '' then display="correct";


Advance thanks

Trusted Advisor
Posts: 3,215

Re: IF else cond not working

Would review the concepts of missing values: SAS(R) 9.4 Language Reference: Concepts and more in detail working with them. SAS(R) 9.4 Language Reference: Concepts  It is the . being used as default representation of missing with numeric variables. With character vars it is ' ' the space. Special missing are possible as sometimes you have more reasons that something is missing.

The usage of the word null is coming from a DBMS point of view that is not the same approach as missing in statistics.

When you are going for statistics try to see that difference and understand the origins.

Going to you question.

You have read the char-variables with "." content in the datastep.

That is really meaningful content for strings these are not missing values.  

---->-- ja karman --<-----
Super User
Super User
Posts: 8,069

Re: IF else cond not working

What is doing that you do not want?

Obs    id     name     gender    display

1     101    rakesh    kumar

2     102              goyal

3     103    namita              correct

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation