SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

flagging an observation

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

flagging an observation

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!

 


Accepted Solutions
Solution
2 weeks ago
Contributor
Posts: 39

Re: flagging an observation

Posted in reply to pmpradhan
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


All Replies
Solution
2 weeks ago
Contributor
Posts: 39

Re: flagging an observation

Posted in reply to pmpradhan
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!
Super User
Posts: 2,078

Re: flagging an observation

[ Edited ]
Posted in reply to pmpradhan

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!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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