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

I have a date in my data named actual_dlvry_date. It looks like this:

 

05/21/2016

 

ad_dt_char=PUT(datepart(actual_dlvry_date), mmddyy10.); * Convert to a char value ;

I'm attempting to make a character version of the date using this code, but my date value comes out as:

 

01/01/1960

 

Any suggestions for what I may be doing wrong here?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Remove the DATEPART.

 

DATEPART assumes the variable is a datetime which is a count of seconds at heart. Date values are counts of days. So since there are many fewer days when treated as seconds the date portion is often going to correspond to 0 or the base SAS date of 1/1/1960.

View solution in original post

3 REPLIES 3
ballardw
Super User

Remove the DATEPART.

 

DATEPART assumes the variable is a datetime which is a count of seconds at heart. Date values are counts of days. So since there are many fewer days when treated as seconds the date portion is often going to correspond to 0 or the base SAS date of 1/1/1960.

buechler66
Barite | Level 11
Thanks so much. That did the trick. I appreciate your help.
JediApprentice
Pyrite | Level 9

The datepart function is used to extract the date from a datetime value. Your date is not a datetime value, datetime values look like 01feb94:8:45. To convert your number date to character, you simply need a put statement with no datepart. Like this:

 

ad_dt_char=PUT(actual_dlvry_date, mmddyy10.); * Convert to a char value ; 

 

Does this answer your question?

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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