Dear,
In my datasets the following values present. my code works for all obs except these obs. Please help thanks.
ex
id exdate exdose
1 09MAY2016 50
1 09MAY2016 100
ae
id aedate
1 09MAY2016
code;
proc sql;
create table dose as
select a.*,b.exdose
from ae as a left join EX as b
on a.id=b.id and a.Aedate-b.exdate >=0
group by a.id,a.aedate
having a.Aedate-b.exdate1=min(a.Aedate-b.exdate);
quit;
output getting ;
id aedate exdose
1 09MAY2016 50
output need;
id aedate exdose
1 09MAY2016 100
Can you provide one liner how the data to be picked for the output. Is it maximum of of exdose or minimum of exdose Or is there any other logic. what condition are applied on dates?
Thanks for help.
I need to get the last dose taken on or before AE start date. My code worked for all obs except this obs because there are two doses taken on the day AE started. I need to get the maximum dose taken on that day. Thanks
You need a way to retain the maximum dose when there are multiple EX records on a date. In addition you have to retain the most recent EXDOSE in cas you encounter a date with an AE record but no EX record:
data want (rename=(date=aedate) drop=prior_dose);
merge ae (rename=(aedate=date))
ex (in=inex keep=id exdate exdose rename=(exdate=date));
by id date;
retain prior_dose;
if first.id then prior_dose=.;
if inex then do;
if first.date then prior_dose=exdose;
else exdose=max(exdose,prior_dose);
end;
else exdose=prior_dose;
if inae;
run;
You have multiple obs for the same date and same id. Keep the last one you want. proc sort data=ex;by id exdate;run; data new_ex; set ex; by id exdate; if last.exdate; run; then PROC SQL.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.