BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
novinosrin
Tourmaline | Level 20

Ah I see @NickS2  I think still hung over from last night. My apologies. Try this

 

data want;
 do until(last.id);
  set have;
  by id ;
  trt_flag=' ';
  if visit=1 and ENROL_FLAG = "Y"  then do;
   trt_flag="Y";
   _n_=0;
  end;
  else if _n_ and ENROL_FLAG = "Y" and DAY_DIFF>180 then trt_flag="Y";
  if not _d and trt_flag="Y" then _d=date;
  if _d and date>=_d then output;
 end;
drop _d; 
run;

 

NickS2
Obsidian | Level 7

@novinosrin 

This is exactly what I wanted. Thank you so much, you are a life saver.

Jagadishkatam
Amethyst | Level 16

please try the below code

 

proc sort data=have;
by id drug date;
run;

data want;
set have;
by id drug date;
if first.drug and ENROL_FLAG='Y' then TRT_FLAG=ENROL_FLAG;
if not first.drug and ENROL_FLAG='Y' and  DAY_DIFF>180 then TRT_FLAG=ENROL_FLAG;
run;
Thanks,
Jag
NickS2
Obsidian | Level 7

Thanks Jagdish,

 

But youe code is giving me the same result which I am getting.

 

 

mklangley
Lapis Lazuli | Level 10

@NickS2 

 

Shouldn't the visit for patient 2 on 26JUN2016 (drug B) be flagged as TRT_FLAG = Y? Your desired output lists it as blank. The first criteria is not satisfied (since the patient already has had drug B), but the second is (ENROL_FLAG = Y and DAY_DIFF > 180).

NickS2
Obsidian | Level 7

@mklangley No the second record for the patient ID 2 should be not get flagged because the first record already met the criteria.

 

 

PGStats
Opal | Level 21

I think the proper logic would look like this:

 


proc sort data=have; by id drug date; run;

data want;
retain flagged;
set have; by id drug;
if first.drug then flagged = 0;
if not flagged then if ENROL_FLAG="Y" or DAY_DIFF > 180 then do;
    flagged = 1;
    TRT_FLAG = "Y";
    end;
drop flagged;
run;

proc sort data=want; by id date drug; run;
PG

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 21 replies
  • 1610 views
  • 2 likes
  • 6 in conversation