BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
raheleh22
Obsidian | Level 7

Hi, 

I am having hard time opening a data using infile statement. here is my code and I do not know why it is giving the error of "0" 0bservations! I know how to do it with proc import but I want to find out why infile statement is not working. 

DATA example;
INFILE 'Location\example.xlsx' DSD FIRSTOBS=2; /* first obesrvation will be second row*/
INPUT patient encounter smoking weight bloodpressure;
RUN;
PROC PRINT DATA=example;
RUN;

 

Thanks a lot, 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

INFILE in combination with INPUT is mainly for reading text files (which are the main vehicle for the transfer of data in professional environments).

Excel (.xslx) files are ZIP-compressed archives of multiple XML files which contain and describe the data.

If you want to use something other than PROC IMPORT or LIBNAME XLSX, you need to use a fileref of type ZIP, read the members (the .xml files) separately and parse the XML.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Since Excel files are not really the same as plain text files, trying to read them with a data step as if they were plain text files will almost definitely not give the desired results. What happens if you use PROC IMPORT instead?

 

proc import datafile="Location\example.xlsx" dbms=excel out=example;
     getnames=YES;
run;
--
Paige Miller
raheleh22
Obsidian | Level 7

I am able to get results with proc import. I was just wondering why infile statement is not working. thanks for your response.

Kurt_Bremser
Super User

INFILE in combination with INPUT is mainly for reading text files (which are the main vehicle for the transfer of data in professional environments).

Excel (.xslx) files are ZIP-compressed archives of multiple XML files which contain and describe the data.

If you want to use something other than PROC IMPORT or LIBNAME XLSX, you need to use a fileref of type ZIP, read the members (the .xml files) separately and parse the XML.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 3 replies
  • 1940 views
  • 1 like
  • 3 in conversation