I need to find minimum of two dates.
I know I can use min function.
q.what precautions do I need to follow?
Ex min(d1,d2)
q.d1,d2 should be in same format?
Here is the requirement.
proc sql;
create table l1
select
termdate format=datetime21.
from t1;
quit;
proc sql;
select min(today()-1,termdate) as testdate format=datetime21.
from l1,l2;
where l1.id=l2.id;
quit;
termdate output testdate
1)
31DEC9999:00:00:00 20FEB20122)
30APR2006:00:00:00 20FEB2012
Q) here there are no errors. But for two different termdate inputs I am getting the same output?
As long as they are date (numeric), format does not matter.
Haikuo
PROC SQL;
SELECT CASE WHEN DATE1<DATE2 THEN DATE1 ELSE DATE2 END AS MIN_DATE FORMAT MMDDYY10. FROM TEST;
QUIT;
I think using min() as OP suggested is safer. '<' will capture missing values as the smaller date, which I suppose not OP's intention.
Kindly Regards,
Haikuo
Comparing datetime. and date directly will be missleading, saying that I would like to retreat my original comments on the format part. Try the following:
proc sql;
select min(today()-1,datepart(termdate)) as testdate format=datetime21.
from l1,l2;
where l1.id=l2.id;
quit;
Regards,
Haikuo
Or, if the time is also important,
select min(datetime()-(24*60*60),termdate) as testdate format=datetime21.
otherwise,make sure that the format is consistent
Considerably the best approach so far, Art! if ')' was added would be perfect!![]()
Kindly Regards,
Haikuo
Corrected it. Thanks for pointing out my typo.
Can you post some sample data.
Maybe you miss a group by clause.
Ksharp
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.