BookmarkSubscribeRSS Feed
SASuserlot
Barite | Level 11

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. 

SASuserlot_1-1604272147323.png

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;
2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Your needs are unclear.

Please provide less test data and more explanations.

SASuserlot
Barite | Level 11
I provided the sas code! Which generate the test dataset. May be u missed it

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 505 views
  • 0 likes
  • 2 in conversation