BookmarkSubscribeRSS Feed
Nehanzh
Calcite | Level 5
While doing proc import of ab xlsx file sas converts short date to sas date format in character and unable convert it in date format. E.g.- date in excel- 10/4/2019. After proc import date- 43742 in char. After converting it to date with this code: format date_1 mmddyy8.;
Date_1=date; the output date_1=10/05/79. Any help?
2 REPLIES 2
Kurt_Bremser
Super User

First of all, do not (as in NOT) use two-digit years, or formats that display only 2 year digits for dates. It only causes confusion, for no gain.

 

If you got the raw Excel value in a date, add

'30dec1899'd

to it, and you'll get the correct date in SAS.

This value covers three things:

  1. Excel starts (nominally, see 3.) at 1900-01-01, SAS starts at 1960-01-01
  2. Excel starts with day 1, SAS with day 0
  3. Excel has a bug that makes it consider 1900 a leap year
jarapoch
Obsidian | Level 7

I'm sending you a link to a post talking about conversion from Excel dates to SAS dates.

 

https://communities.sas.com/t5/SAS-Tips-from-the-Community/SAS-Tip-Conversion-from-Excel-Date-to-SAS...

 

Maybe you can use  SAS_date = Excel_date - 21916;  to convert your Excel date to a SAS date.

 

Just one thing, you'll have to convert your character variable "date" to a numeric variable using INPUT (eg: numeric_date = input(date, 8.))

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1032 views
  • 1 like
  • 3 in conversation