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

Hi,

 

I am trying to import an excel file into SAS EG, every time I do this however the numbers appear different to what they are in the spread sheet. I am also struggling with date formats

 

here is an exmaple of the excel file I am changing, the first column is a DOB, middle column is a Idenfier number and the last column is date registered;

 

3091991140000000003315012018
17031977140000000004415012018
3101982140000000005516012018

 

After importing to SAS the columns and rows appear as below, the date columns do not register as a dates and the identifier number becomes what can be seen below.

 

30919911.4E+1215012018
170319771.4E+1215012018
31019821.4E+1216012018

 

What I basically want to do is import the excel file with the correct formats for each column. dates as dates and the indentifier number as full number.

 

Can you help this please?

 

S

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This is because Excel is a bad data format, and I assume you are using proc import which is a guessing procedure.  Combine the two and what you get out will be garbage half the time.

From the Excel data create a CSV file - plain text, delimited, cross platform, easy to use = much better than Excel.

Write a datastep import program (you can take the shell from the log after a proc import has run to save time), and apply in the datastep formats, informats, lengths etc.  Eg:

data want;
  infile ".../myfile.csv";
  length ...;
  format ...;
  informat ...;
  input ...;
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This is because Excel is a bad data format, and I assume you are using proc import which is a guessing procedure.  Combine the two and what you get out will be garbage half the time.

From the Excel data create a CSV file - plain text, delimited, cross platform, easy to use = much better than Excel.

Write a datastep import program (you can take the shell from the log after a proc import has run to save time), and apply in the datastep formats, informats, lengths etc.  Eg:

data want;
  infile ".../myfile.csv";
  length ...;
  format ...;
  informat ...;
  input ...;
run;
Tom
Super User Tom
Super User

Your example looks fine to me.  It is just that the numbers in your second column are too large to display using the default BEST12. format.  Just use a different format to display them.

 

But they also look like they might really be identifiers instead of numbers that you are going to use in calculations. In that case if you convert them to strings in Excel then SAS will import them as character strings instead.

 

Your third column is NOT a date in Excel, why would you expect it to appears as a date in SAS?

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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