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

Hi,

 

I have two date fields in the original excel file, both are in the format of MM/DD/YYYY. However, when the data was imported, one was imported with the datetime format and the other was imported as a character field with the number values like 18482 for 8/7/1950.

 

Does anyone can help explain why the date fields were imported differently? How can I get the right format for them, especially the one imported as character?

 

Thanks a lot!

Lizi

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If it imported as character it is because the column has at least one cell with character values in it.

When that happens instead of getting the formatted values of the dates you get the actual number that Excel uses to store dates converting to a string of digits.

The real solution is to fix the Excel file so that all cells in the column contain dates and not strings.

If you cannot do that there are other questions on this site with answers for how to convert those strings to numbers and subtract the right number to get them converted to SAS date values.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

If it imported as character it is because the column has at least one cell with character values in it.

When that happens instead of getting the formatted values of the dates you get the actual number that Excel uses to store dates converting to a string of digits.

The real solution is to fix the Excel file so that all cells in the column contain dates and not strings.

If you cannot do that there are other questions on this site with answers for how to convert those strings to numbers and subtract the right number to get them converted to SAS date values.

lizzy28
Quartz | Level 8

Thanks a lot Tom! You are right. There are indeed a couple of string values in the original data.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 4034 views
  • 0 likes
  • 2 in conversation