Is there an easy way to create WANT column with data having fields ID, DATE and HAVE column without using lag -
| ID | DATE | Have | Want |
| A | 30-Jun-06 | 1 | 30-Jun-06 |
| A | 31-Jul-06 | 1 | 30-Jun-06 |
| A | 31-Aug-06 | 1 | 30-Jun-06 |
| A | 30-Sep-06 | 1 | 30-Jun-06 |
| A | 31-Oct-06 | 1 | 30-Jun-06 |
| A | 30-Nov-06 | 0 | |
| A | 31-Dec-06 | 0 | |
| B | 30-Jun-06 | 0 | |
| B | 31-Jul-06 | 0 | |
| B | 31-Aug-06 | 0 | |
| B | 30-Sep-06 | 0 | |
| B | 31-Oct-06 | 1 | 31-Oct-06 |
| B | 30-Nov-06 | 1 | 31-Oct-06 |
| B | 31-Dec-06 | 1 | 31-Oct-06 |
| C | 30-Jun-06 | 0 | |
| C | 31-Jul-06 | 1 | 31-Jul-06 |
| C | 31-Aug-06 | 1 | 31-Jul-06 |
| C | 30-Sep-06 | 0 | |
| C | 31-Oct-06 | 0 | |
| C | 30-Nov-06 | 1 | 30-Nov-06 |
| C | 31-Dec-06 | 1 | 30-Nov-06 |
Something like this may work (not tested):
data data_want;
set data_have;
by id have notsorted;
if first.have then do;
if have=1 then want=date;
else call missing(want);
end;
retain want;
run;
Something like this may work (not tested):
data data_want;
set data_have;
by id have notsorted;
if first.have then do;
if have=1 then want=date;
else call missing(want);
end;
retain want;
run;
Many thanks, that works!
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.