Difference between INFILE AND IMPORT

Posts: 21

Difference between INFILE AND IMPORT

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?

Super Contributor
Posts: 276

Re: Difference between INFILE AND IMPORT

Posted in reply to sridhar78


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




Super Contributor
Posts: 644

Re: Difference between INFILE AND IMPORT

Posted in reply to sridhar78

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.


Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation