SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
srdr1217
Calcite | Level 5

What is Infile and file statements in SAS and what is the difference between them?

2 REPLIES 2
Kurt_Bremser
Super User

INFILE is used to denote an external file from whcih data is read into the SAS system.

FILE denotes an external file that data is written to.

 

Basic DATA step architecture:

 

DATA test;

INFILE "external_file.txt";

INPUT

  x1

  x2

;

RUN;

 

DATA _NULL_;

SET test;

FILE "another_external_file.txt";

PUT

  x1

  x2

;

RUN;

MikeZdeb
Rhodochrosite | Level 12

Hi ... you can try this ...

 

* create a data file (no data set created);

data _null_;

* specify the name of the data file;

file 'c:\new.txt';

* create some numeric variables and give them all a value of 99;

retain x1 x2 x3 99;

* write the values of the variables to the file specified in the FILE statement;

put x1-x3;

run;

 

* read the data file you just created and create a data set;

data new;

* specify the location of the data file;

infile 'c:\new.txt';

* read the data;

input x1-x3;

run;

 

* look at your data set;

proc print data=new;

run;

 

Another way to remember the difference between FILE and INFILE is to think of the statements PUT and INPUT.  PUT statements are associated with FILE (write to a file) and INPUT statements are associated with INFILE (read data from an already existing file).

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 7478 views
  • 0 likes
  • 3 in conversation