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!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.