I have a Vital dataset that I created with help of @Kurt_Bremser . I have the requirement to Flag the last available flag for every Param in my dataset. These are my conditions.
Flag last available record where firstdtc>seconddtc ( this will be true for Records where they have status "Post". In that case, I need to flag the records that have the status "Pre")
If any param is missing in the last Visit (Visit 3) then it should flag before Visit where that Param available.
Weight is the exception because it did not have pre or post status. So it should flag in the last available visit for respective subjects. I am attaching the excel pic example, to get an Idea of how the flag"Y" shows up.
data vital;
infile datalines truncover;
input
@1 usubjid :$11.
@13 param :$10.
@23 status :$4.
@29 visit :$7.
@37 _firstdt anydtdte11.
@49 _firsttm time8.
@59 _seconddt anydtdte11.
@71 _secondtm time8.
@81 type :$10.
;
format firstdtc seconddtc e8601dt19.;
firstdtc = dhms(_firstdt,0,0,_firsttm);
seconddtc = dhms(_seconddt,0,0,_secondtm);
drop _:;
datalines;
SD-1001-101 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-102 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 diastolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 systolic post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 temp post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height pre Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 height post Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T10:10:10 2018-MAR-19T10:30:10 first
SD-1001-103 weight Visit1 2018-MAR-19T11:10:10 2018-MAR-19T10:30:10 first
SD-1001-101 diastolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 diastolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-101 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-102 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 systolic post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 temp post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height pre Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 height post Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T10:10:10 2018-MAR-25T10:30:10 second
SD-1001-103 weight Visit2 2018-MAR-25T11:10:10 2018-MAR-25T10:30:10 second
;
run;
Data Vital1;
set vital;
if status="Visi" then status="";
run;
Your needs are unclear.
Please provide less test data and more explanations.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.