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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 21 replies
  • 2389 views
  • 2 likes
  • 6 in conversation