BookmarkSubscribeRSS Feed
sridhar78
Calcite | Level 5

What is the basic difference between Infile and Import statement?

In case of Import SAS reads and raw data and creates a SAS data file. What happens in case of INFILE?

Is there any difference in the format of the data or impact on calculations or making changes to the file?

2 REPLIES 2
kuridisanjeev
Quartz | Level 8

Hi,

Go through bellow paper,Hope this will  answer all your questions.

http://www.wuss.org/proceedings10/TUT/3054_4_TUT-Villacorte.pdf

Regards,

Sanjeev.K

RichardinOz
Quartz | Level 8

IMPORT is a Procedure (Proc), a piece of self contained and precompiled code which accepts various options or parameters to achieve a range of standard import functions.  In a bare bones installation it can write SAS a code data step "under the covers" to read a flat file into a SAS data table.  You can review this code after running Proc Import by issuing a recall (usually F4).

If you have SAS Access to Microsoft (?? not sure of the name) Proc Import does something completely different, using MS utilities to read data from MS Excel or MS Access.  F4 will not reveal any hidden code.

INFILE is a Statement used in the context of a data step to identify the text file you want to read into a data step.  You cannot use Infile as a stand alone statement, it is used within the data step which should also have an INPUT statement to control the data read.  INFILE together with INPUT in a data step is more flexible than the IMPORT procedure because it allows you more control how the data is read.  However, everything has to be manually specified whereas Proc Import will do a best guess for column type, width and informats.  It  is not unusual for the more automated procedure to guess wrong.

So if you have a straightforward CSV or tab delimited text file to read, with not too many missing values, PROC IMPORT will usually satisfy.  If you have a spreadsheet or Access database it is the only choice of these 2 methods (but other options such as using a properly configured libname also exist in recent SAS versions)

If your CSV data is not correctly read, one trick is to do Proc Import, then retrieve the underlying SAS code (F4, note the included an INFILE statement) and edit the informat and format statements to comply with your data.

So INFILE and IMPORT are different animals, not interchangeable.

Richard

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
  • 2 replies
  • 19281 views
  • 7 likes
  • 3 in conversation