BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sdang
Quartz | Level 8

Hi all,

I couldn't figure this out.  I need all your help.  I have a datetime variable -PlayerDayDate-- and I want to convert to look like this "01/Jun/15" so I can join a import file with the date formatted as such "01/Jun/15".

Below is the image of the datetime variable. Below that image is the function I used in Query builder.

PlayerDayDateConvert Result
01Jul2015:00:00:00.0001Jul2015

MDY(datepart(t1.PlayerDayDate),datepart(t1.PlayerDayDate),datepart(t1.PlayerDayDate))

The function above is valid but all I get are blanks rows.  What I have done wrong?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Formats are for display (printing) only. For processing like a comparison/join/... SAS uses the internal values (so: 20269). The format applied is irrelevant.

I believe your data is not matching because 20269 represents a date of 30JUN2015 and that's not the same like 01Jul15.

data _null_;

  dt=20269;

  put "Date is: " dt date7.;

  stop;

run;

Date is: 30JUN15

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

Gong from datetime to date only requires DATEPART:

datepart(t1.PlayerDayDate)

sdang
Quartz | Level 8

Thank you for the reply.  I tried that but when I import a file with dates as "01Jul15" I cannot join the two columns together. I think SAS still reads datepart(T1.PlayerDayDate) as 20269 eventhough I formatted as "01Jul15".

Thanks

SASKiwi
PROC Star

When you apply datepart then you also need to assign a format to the result like date9 so SAS correctly displays it as a date. I don't know what you mean by "I cannot join the two columns together".

sdang
Quartz | Level 8

I want to join datepart(PlayerDayDate) with an imported date column which is in this formatted: 01Jul15.  When I join PlayerDayDate with that imported column, I get blanks.  SAS reads the imported column as 01Jul15 and Datepart(PlayerDayDate) as its numeric value (ie. 20269) not as the formatted date9.

Thanks

Patrick
Opal | Level 21

Formats are for display (printing) only. For processing like a comparison/join/... SAS uses the internal values (so: 20269). The format applied is irrelevant.

I believe your data is not matching because 20269 represents a date of 30JUN2015 and that's not the same like 01Jul15.

data _null_;

  dt=20269;

  put "Date is: " dt date7.;

  stop;

run;

Date is: 30JUN15

sdang
Quartz | Level 8

Thank you for your help.  It worked.

sas-innovate-2024.png

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.

 

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
  • 6 replies
  • 1897 views
  • 0 likes
  • 3 in conversation