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

I have a Date column that has been formatted as a number and the datetime is reflected as a number, eg 1753920000

 

I need to convert this to a date format, eg 20151001 or 01OCT.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Since valid_end_dt1 contains valid SAS datetime values (otherwise the datetime20. format would never work), you can apply the datepart function directly to it. No need for the double conversion.

So your code would be

data VALID_DATE;
set source table;
valid_end_date_1=datepart(valid_end_dt1);
format valid_end_date_1 date5.;
run;

View solution in original post

5 REPLIES 5
sbxkoenk
SAS Super FREQ
data _NULL_;
 a='22JUN2019:23:14:12'dt;
 put a=;
 put a= datetime.;
 b=datepart(a);
 put b=;
 put b= date9.;
run;
DarrylLawrence
Obsidian | Level 7

I solved the problem as follows:

 


data VALID_DATE;
set source table;

valid_end_date_1=datepart(input(put(valid_end_dt1,datetime20.),datetime20.));

format valid_end_date_1 date5. ;
run;

 

Results:

 

VALID_END_DT1 VALID_END_DATE_1
1753920000 31-Jul
1753920000 31-Jul

 

 

 

Kurt_Bremser
Super User

Since valid_end_dt1 contains valid SAS datetime values (otherwise the datetime20. format would never work), you can apply the datepart function directly to it. No need for the double conversion.

So your code would be

data VALID_DATE;
set source table;
valid_end_date_1=datepart(valid_end_dt1);
format valid_end_date_1 date5.;
run;
DarrylLawrence
Obsidian | Level 7
Thanks Kurt, it works!
Peter_C
Rhodochrosite | Level 12
Rather than use datepart() function to convert the value, you could use the DTDATE. format to present just the date without any other conversion.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1208 views
  • 3 likes
  • 4 in conversation