BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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

4 REPLIES 4
RahulG
Barite | Level 11

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?

knveraraju91
Barite | Level 11

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

mkeintz
PROC Star

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;

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Ksharp
Super User
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 723 views
  • 2 likes
  • 4 in conversation