BookmarkSubscribeRSS Feed
zhangda
Fluorite | Level 6

Hello,

 

I am coding a new field 'sex', for the table 'grade',  but why the value is all 'N' but not 'Y', because I insert the value of resp1 into 'Y', which is not supposed to be null. Please guide me. Thanks!

 

data ds1;

input year $ mid $ resp1 resp2;

mid2=cat(strip(mid), "_2");

datalines;

null d_2016 0.45 0.64

null d_2015 0.35 0.783

s_300 d_2016 0.65 0.67

s_300 d_2015 0.55 0.75

s_640 d_2016 0.42 0.89

s_640 d_2015 0.65 0.87

s_670 d_2016 0.35 0.12

s_670 d_2015 0.75 0.09

s_700 d_2016 0.83 0.06

s_700 d_2015 0.47 0.07

s_730 d_2016 0.48 0.18

s_730 d_2015 0.58 0.21

s_760 d_2016 0.67 0.05

s_760 d_2015 0.69 0.045

;

run;

 

proc sql;

create table grade as

select * ,

case when resp2 <>0 then 'N'

when resp1 <>0 then 'Y'

else 'Other' end as Sex

from ds1; quit;

 

 

3 REPLIES 3
Reeza
Super User

Case statements are evaluated in the order they appear. 

Since your first condition is always true you never reach the second condition. 

ballardw
Super User

This statement is true for all of your example data

resp2 <>0

so the evaluation of that line sets everything to "N"

 

If you are using SAS you want to think "missing" instead of "null". SAS has specific functions to deal with missing and does not use the concept "null".

 

Also you use <> which SAS is going to treat as "return the maximum value of the two values compared" and not what I believe you meant by "not equal". And SAS treats any non-zero value that is not missing as "True".

Reeza
Super User

SQL treats <> as not equals

Data step (not Where) treats it as maximum

 

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 1268 views
  • 2 likes
  • 3 in conversation