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

 

 

 

 


 

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!

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