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

Hi

Attached is the screenshot of the data. 

In the data for trt1 if the dose taken should be 90 mg for seven days and then it should be 180 mg.

For trt2 it is 250 mg for all days. If the subject has dose reduced continuously for 3 days then those records should be flagged. 

After the dose reduction period if the subject has again got back to his scheduled dose then that should be flagged as dose returned. 

This will only be flagged for immediate records after the dose reduction.

And count the longest duration of dose reduction for subject based on dose. 

eg if the subject to 60 mg for 30 days and 100 mg for 80 days then 80 days would be the long duration. 

we need to sum the days consecutively 

eg; if the subject took 30 mg from jan1 to jan 15 then the count is 15 days of duration 

  60 mg from jan16 to jan 30 then the count is 15 days

 30 mg for feb1 to feb 20 then count is again 20. 

 

code:

 

proc sort data= adex_; by usubjid ectrt ecstdtc ecendtc ; run;

 

data y1;

set adex_;

by usubjid ectrt ecstdtc ecendtc ;

where ecdose > 0 ;

run;

 

data y2;

set y1;

do impdt= ecstdtn to enddate;

output;

end;

format impdt date9.;

keep usubjid ectrt trtp trta ecstdtc ecendtc   

enddate ecendtn ecstdtn  ecdosfrq frq  ecdose impdt;

run;

 

 

proc sort data= y2; by usubjid ectrt ecstdtc ecendtc ; run;

 

data frstdt(keep = usubjid ectrt ecstdtn rename= (ecstdtn= frstdt))

   lstdt (keep = usubjid ectrt enddate rename= (enddate= lstdt));

  set y2;

  by usubjid ectrt ecstdtc ecendtc ;

  if first.ectrt then output frstdt;

  if last.ectrt then output lstdt;

  run;

  proc sort data= y2; by usubjid ectrt; run;

  proc sort data= frstdt; by usubjid ectrt ; run;

  proc sort data= lstdt; by usubjid ectrt ; run;

 

  data y2_;

  merge y2(in=a) frstdt lstdt ;

  by usubjid ectrt ;

  if a;

  impdy= impdt- frstdt +1 ;

  if index (ectrt, "TRT1")  and .<impdy<=7 then do; expdos= 90; expfrq=1;end;

else if index (ectrt, "TRT1")  and impdy>7 then do; expdos= 180; expfrq=1;end;

else if index (ectrt, "TRT2") then do; expdos =250; expfrq=2; end;

doser = ecdose*frq;

expdoser= expdos*expfrq;

if doser < expdoser then redflg ='Y';

run;

 

proc sort data= y2_; by usubjid ectrt ecstdtn impdt ; run;

 

data y3;

set y2_;

by usubjid ectrt ecstdtn impdt   ;

if first.ectrt then seq =1;

else seq+1 ;

run;

 

proc sort data= y3 ; by usubjid ectrt ecdose ecstdtn impdt ; run ;

 

data w1;

set y3;

by usubjid ectrt ecdose ecstdtn impdt;

lgdt= lag(impdt);

if first.ecdose then lgdt= impdt ;

if  ecstdtn= impdt then diff = 1;

else if first.ecdose then diff = impdt- lgdt +1;

else diff= impdt- lgdt ;

format lgdt date9.;

run;

 

data want;

set w1;

by usubjid ectrt diff redflg notsorted;

retain _date;

if first.redflg then do;_date=impdt;n=0; end;

n+1;

if last.redflg and not missing(redflg) then output;

format _date date9.;

run;

 

proc sort data= want out= chk nodupkey;

where n >=3 ;

by usubjid ectrt ;

  run;

 

We cannot sum the first 15 and 30 days of the 30 mg if there is a different dose between them. 

If the dose is same then we need to club and count the duration. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
andreas_lds
Jade | Level 19

@yashraj89 wrote:

Hi

Attached is the screenshot of the data. 

[...]

 


 

Please post the data in usable form.

yashraj89
Obsidian | Level 7

SAS dataset is attached here.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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