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 | B | Flag |
| . | 65 | . |
| . | 12 | . |
| 626 | 5 | 0 |
| 20 | . | . |
| . | 23 | . |
| 10 | 25 | 1 |
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!
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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.