简体   繁体   中英

SAS SQL : Date compare

Hi i have a question for comparing two dates in SAS Proc SQL

-Condition-

Date_A(Fixed) : 2020-11-08
Date_B : 2020-12-15 or 2020-12-UN => Date_B Could be 2020-12-UN (UNknown Day)

So, what i did is...

Select A.DATE, B.DATE
From A.TABLE, B.TABLE
Where (input(Scan(Date_B,2,'-'),best10.) < input(Scan(Date_A,2,'-',best10.)) or Date_B < Date_A

-First, If Date_B's Day is 'UN', Compare with 'Month' If not simple compare..

But..its not working (even know why)

Is there any other way..?

with kind regards

Hopefully this helps, though its possible your question isn't specific enough in detail... this will compare the dates as requested, but is unlikely to give you useful output (!)
This assumes the dates are strings, given the "UN" element.

Select case when substr(A.DATE,9)='UN' then substr(A.DATE,1,7)
else A.DATE end as DATE_A
, case when length(calculated DATE_A)=7 then substr(B.DATE,1,7)
else B.DATE end as DATE_B
From A.TABLE, B.TABLE
where calculated DATE_A < calculated DATE_B

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM