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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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