BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pmpradhan
Quartz | Level 8

My data looks like below without the flag, I want to create a flag that has the value of 1 when B> A (0 when reverse is true)and it should be missing when either A or B has a missing value.

 

A      BFlag
.       65.
.      12.
626  50
20   ..
.       23.
10251

 

I have tried this;

data X;
set Y;
if (A ne .) or (B ne .) and B >A then flag=1;

else flag=0;
run;

 

and didn't work. 

 

Please help!

 

1 ACCEPTED SOLUTION

Accepted Solutions
pmpradhan
Quartz | Level 8
data x;
set y;
if A =. then flag=.;
else if B=. then flag=.;
else if B>A then flag=1;
else if A >B then flag=0;
run;
Coding for each condition gave me result!

View solution in original post

2 REPLIES 2
pmpradhan
Quartz | Level 8
data x;
set y;
if A =. then flag=.;
else if B=. then flag=.;
else if B>A then flag=1;
else if A >B then flag=0;
run;
Coding for each condition gave me result!
novinosrin
Tourmaline | Level 20

data want;
set have;
if nmiss(a,b)=0 then flag=b>a;
run;

 

EDIT: I really appreciate you self attempt and effort to get a working code. However, once you throw  open a thread in the community, you are sure to get some robust solutions. But well done mate!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 680 views
  • 0 likes
  • 2 in conversation