BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
x2PSx
Calcite | Level 5

Hello,

 

Using SAS EG 8.3 and I'm trying to do a left join between two tables using dates and a proc sql.

 

One table has a date variable with these properties:

Type: Numeric

Group: Date

Format: YYMMDD10.

Informat: YYMMDD10.

Values are displayed like this: 2023-09-15

 

 

The other table has a date variable with these properties:

Type: Numeric

Group: Date

Format: DATETIME.

Informat: ANYDTDTM40.

Values are displayed like this: 15Sep2023 0:00:00

 

Could someone help me with the transformation I have to do to make this join happen?

Thank you very much!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

It would have been nice to have detail like variable names.

You want to use the DATEPART function on the Datetime variable to pull the date for comparison with any date value

 

So and ON clause for a joint might look like:

on a.datevariable = datepart(b.datetimevariable)

if you want to match a specific time then you would add the time portion to the date which is easy with the DHMS function:

on dhms(a.datevariable,12,15,0) = b.datetimevariable

for example would match on the date plus when hour=12 and minutes=15 and seconds=0 in both variables.

View solution in original post

2 REPLIES 2
ballardw
Super User

It would have been nice to have detail like variable names.

You want to use the DATEPART function on the Datetime variable to pull the date for comparison with any date value

 

So and ON clause for a joint might look like:

on a.datevariable = datepart(b.datetimevariable)

if you want to match a specific time then you would add the time portion to the date which is easy with the DHMS function:

on dhms(a.datevariable,12,15,0) = b.datetimevariable

for example would match on the date plus when hour=12 and minutes=15 and seconds=0 in both variables.

x2PSx
Calcite | Level 5
The datepart function did the trick, thank you for your time ballardw!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2112 views
  • 2 likes
  • 2 in conversation