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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 266 views
  • 1 like
  • 3 in conversation