BookmarkSubscribeRSS Feed
mehong19
Obsidian | Level 7
I imported an excel file with date information enclosed as a format of mm/dd/yyyy (e.g. 11/1/1997) in Excel. After importing into SAS, the format changed automatically into a series of numbers and variable type is character. I converted character into numeric and used DATE9. format. However, I got the different date for the same record. e.g. 11/1/1997 changed to 02NOV2057.
 
My goal is to keep the original date info and its format as they are after importing.
 
Two image files attached for reference. Thanks in advance.
 
 

excel_image.pngSASoutput_image.png
3 REPLIES 3
AndrewHowell
Moderator

Can you please tell us HOW you imported the Excel spreadsheet into SAS?

 

For example:

  • PROC IMPORT..
  • LIBNAME EXCEL..
  • Using the EG "Import Data" task
  • other?

Including code & logs would would also assist us in assisting you.

 

ballardw
Super User

If you used Proc Import to bring the data into SAS you may have fallen somewhat afoul of user data entry and/or other EXCEL behavior. Proc Import uses what the Excel data engine tells SAS the data is in the first few rows. So if you have any data in the data column that is not in exactly the same form as the top 20 rows it gets treated as if it were that format. An obnoxious bit about Excel is depending on how users enter data you may create an Excel date value or a string. The conversion is not the same.

 

When data is entered manually it may be necessary to highlight your date columns and change the entire column to one type and set the format for all of the cells the same. I usually export to CSV and import that as I have more control and some other issues become more obvious such as changing lengths of charater variables that are supposed to be the same in different files.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1590 views
  • 0 likes
  • 4 in conversation