BookmarkSubscribeRSS Feed
Ross12345
Calcite | Level 5

I never have an easy time converting dates in this language.

 

I imported a set of dates from an excel sheet that follow the form "2016/02/23 18:24:00"

Once loaded they have the following properties:

Type: Char

Len: 27

 

I would like to convert them to a workable SAS date format (date9.). I tried a number of approaches without success - online resources aren't super helpful when it comes to SAS date formats.

 

Please advise

 

 

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26
data example;
    datetime_char="2016/02/23 18:24:00";
    datetime_want=input(datetime_char,anydtdtm.);
    date_want=datepart(datetime_want);
    format datetime_want datetime18. date_want date9.;
run;
--
Paige Miller
ballardw
Super User

@Ross12345 wrote:

I never have an easy time converting dates in this language.

 

I imported a set of dates from an excel sheet that follow the form "2016/02/23 18:24:00"

Once loaded they have the following properties:

Type: Char

Len: 27

 

I would like to convert them to a workable SAS date format (date9.). I tried a number of approaches without success - online resources aren't super helpful when it comes to SAS date formats.

 

Please advise


Part of the issue is that "dates" in Excel sometimes aren't. I've had to process files where half the dates were entered as character values. So even Excel couldn't treat them as dates, or more properly, datetime values.

 

It might help to share the approaches that did not work and exactly why they didn't.

 

BTW, this is an "online resource" and we get to answer this question in one form or another at least once a week.

 

 

Reeza
Super User

Here's a great, but longer and in depth, reference for dates and times in SAS
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

 


@Ross12345 wrote:

I never have an easy time converting dates in this language.

 

I imported a set of dates from an excel sheet that follow the form "2016/02/23 18:24:00"

Once loaded they have the following properties:

Type: Char

Len: 27

 

I would like to convert them to a workable SAS date format (date9.). I tried a number of approaches without success - online resources aren't super helpful when it comes to SAS date formats.

 

Please advise

 

 

 

 


 

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