Hi, how do I use min() and max() function in PROC SQL to get the right dates (earliest and latest dates) from a list of visit dates?
I feel like my code is right, but I'm getting a format wrong. PROC SQL is using the min/max functions correctly within the same months (02FEB2009 is less than 19FEB2009), but the functions mess up when the months are different (02NOV2009 is incorrectly less than 10OCT2009).
Please help!!! A million thanks to the wonderful SAS community 😁.
options fmtsearch=(lookup);
data aggreg;
set svisit1-svisit&vars;
by USUBJID VISITNUM rawdtc;
VISIT=put(compress(put(VISITNUM,3.)),$VISITPRJ5457_VISIT.);
rawdtc2=put(input(rawdtc,E8601DA10.),date10.);
run;
proc sort data=aggreg out=aggreg2;
by USUBJID VISIT rawdtc2;
Proc sql;
create table xo as
select USUBJID, VISIT, VISITNUM, rawdtc2,
min(rawdtc2) as min_date,
max(rawdtc2) as max_date
from aggreg2
group by USUBJID, VISIT;
RAWDTC2 is a string, therefore April comes before February.
Replace
rawdtc2=put(input(rawdtc,E8601DA10.),date10.);
with
rawdtc2=input(rawdtc,E8601DA10.);
to have a date
RAWDTC2 is a string, therefore April comes before February.
Replace
rawdtc2=put(input(rawdtc,E8601DA10.),date10.);
with
rawdtc2=input(rawdtc,E8601DA10.);
to have a date
Thank you so much!!!
I've been staring at this error for an hour.
So grateful for your quick help 🐕!!!
@anonymous_user, glad it is now working.
For best practice and further appreciation, you should be able to accept the response from @ChrisNZ as the solution (not my post).
Kind regards,
Amir.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.