Dear Everyone,
May I please ask how do we get the last column, 'flag' given my input data containing id, date, vis and site?
I would like to be able to flag the most recent non-missing var from a visit given the date by site for patients.
Your help is very much appreciated.
id date vis site var flag
1 01-Jan-2020 1 1 1
1 02-Feb-2020 2 1 10 1
1 03-Mar-2020 3 1 11 0
1 10-Mar-2020 3 1 12 1
1 05-Apr-2020 4 1 11 1
1 06-May-2020 5 1 9 1
1 07-Jun-2020 6 1 . 0
1 06-Jun-2020 6 1 13 1
1 09-Aug-2020 8 1 10 1
1 01-Jan-2020 1 2 9 1
1 02-Feb-2020 2 2 7 1
1 03-Mar-2020 3 2 5 1
1 10-Mar-2020 3 2 7 1
1 05-Apr-2020 4 2 8 1
1 06-May-2020 5 2 . 1
1 07-Jun-2020 6 2 7 1
1 25-Aug-2020 8 2 . 0
1 09-Aug-2020 8 2 10 1
2 01-Jan-2020 1 1 4 1
2 02-Feb-2020 2 1 10 1
2 03-Mar-2020 3 1 11 0
2 10-Mar-2020 3 1 12 1
2 05-Apr-2020 4 1 11 1
2 06-May-2020 5 1 9 1
2 07-Jun-2020 6 1 9 1
2 25-Jun-2020 7 1 13 1
2 09-Aug-2020 8 1 10 1
2 01-Jan-2020 1 2 9 1
2 02-Feb-2020 2 2 7 1
2 03-Mar-2020 3 2 5 0
2 10-Mar-2020 3 2 7 1
2 05-Apr-2020 4 2 8 1
2 06-May-2020 5 2 6 1
2 07-Jun-2020 6 2 7 1
2 31-Aug-2020 8 2 20 1
2 09-Aug-2020 8 2 10 0
With id = 1, site = 1, and vis = 3, you flag both observations as 1, but with id = 2, site = 2, vis = 8, you only flag the later as 1; what is the difference here?
Thanks @Kurt_Bremser for pointing out.
Post is now corrected.
Try this:
proc sort data=have;
by id site vis date;
run;
data want;
set have;
by id site vis;
flag = last.vis;
run;
Thanks @Kurt_Bremser for trying to help 😊
I managed to get it done correctly by following this post here instead
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.