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

Hi,

i would import a file excel but i have a problem:

 

PROC IMPORT OUT= WORK.example   
DATAFILE= "C:\Users\ui43925\Desktop\example.XLSX"
            DBMS=EXCEL REPLACE;
     SHEET="example"; 
     GETNAMES=YES;
     MIXED=YES;
     SCANTEXT=YES;
     USEDATE=YES;
     SCANTIME=YES;
RUN;

problem.PNG

 

 

After import, in the table sas the column "Ora format" and "Hour" isn't format timestamt but in DATE9., what is my fault ?

Thanks!!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If XLSX doesn't work you can look into DBSASTYPE but your options are limited. 

 

You'll either need to convert to CSV, which can be automared, or accept a date variable. 

View solution in original post

15 REPLIES 15
Cello23
Quartz | Level 8

In attachments the file.

thanks

Tom
Super User Tom
Super User

What version of SAS are you running? I was able to read that file using SAS 9.4 using the XLSX engine without any issue.

%let path=C:\downloads;
libname x xlsx "&path/example.xlsx";
proc print data=x.example (obs=10); run;

 

Capture.JPG

andreas_lds
Jade | Level 19

Have you tried using libname instead of proc import? Have you tried replacing the format after importing?

Cello23
Quartz | Level 8

with libnam is the same problem:

libname xls "C:\Users\ui43925\Desktop\example.xlsx";

 

convert datatime9. in timestamt isn't possibile (lenght 8):

errore_2.JPG

 

Smiley Sad

Reeza
Super User

Use XLSX or EXCEL as the libname engine, not Xls. 

Cello23
Quartz | Level 8
😞
the same problem.

libname prova excel "C:\Users\ui43925\Desktop\example.xlsx";
andreas_lds
Jade | Level 19

Length eight is max for numeric variables and always sufficient for datetime variables.

I have no idea why proc impot does not recognize the datetime as datetime - could be a bug.

 

Easiest way to solve the problem: don't use excel as data-source Smiley Wink

Cello23
Quartz | Level 8
you're right , but i receive this file every day with email attachment, automatically save it with outlook to run query in SAS. I would like to not have manually activities ...
Reeza
Super User

If XLSX doesn't work you can look into DBSASTYPE but your options are limited. 

 

You'll either need to convert to CSV, which can be automared, or accept a date variable. 

Cello23
Quartz | Level 8
Fantastic!!! thanks so much!!!

PROC IMPORT OUT= WORK.example
DATAFILE= "C:\Users\ui43925\Desktop\example.XLSX"
DBMS=EXCEL REPLACE;
SHEET="example";
GETNAMES=YES;
MIXED=YES;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
DBDSOPTS=" SASDATEFMT=('Hour'='DATETIME27.' 'Ora format'='DATETIME27.') ";
RUN;
rogerjdeangelis
Barite | Level 11
R seemed to hadle it very naturally. 

Note I could easily reformat the datetime display with a format, like SAS.
I think the defalt format is either POSIX or ISO.

The main issue is creating a SAS dataset and there is work going on to do this.
R can read SAS datasets.

%utl_submit_r64( library(XLConnect); wb <- loadWorkbook('d:/xls/example.xlsx'); data <- readWorksheet(wb, sheet = 'example'); head(data); ); /* Ora.format Hour 1 2016-05-29 00:00:00 2016-05-29 00:00:00 2 2016-05-29 00:00:00 2016-05-29 00:00:00 3 2016-05-29 01:00:00 2016-05-29 01:00:00 4 2016-05-29 01:00:00 2016-05-29 01:00:00 5 2016-05-29 02:00:00 2016-05-29 02:00:00 */
Reeza
Super User

@rogerjdeangelis But this isn't an R forum? 🤔 I have nothing against R and even use it for consulting but not sure how answer above is relevant given question.  

Cello23
Quartz | Level 8

Sorry, but i don't use R.

Thanks

rogerjdeangelis
Barite | Level 11
Here is a solution the OP can use easily, I just don't see the need for IML and R.

proc iml; submit / R; library(XLConnect) wb <- loadWorkbook('d:/xls/example.xlsx') data <- readWorksheet(wb, sheet = 'example') endsubmit; call importdatasetfromr('data','data'); quit;

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
  • 15 replies
  • 4904 views
  • 7 likes
  • 5 in conversation