Input statement without variables

Reply
New Contributor
Posts: 4

Input statement without variables

[ Edited ]

Hi All,

 

I am new in SAS. Recently I came across a SAS code, Can you please explain me:-

 

data _null_; /* don't need dataset*/

infile in; /* raw file in */

input; /* read a record */

put _infile_; /* put buffer in log*/

if _n_ > 50 then /* stop after 50 */

stop; /* adjust as needed */

run; /* end of step */

 

What is exactly the role/function of input As it is not declaring any variable?

 

Thanks and Regards,

Saket

Super Contributor
Posts: 305

Re: Data _Null_

Hello,

 

This form of input reads the whole line of input data without assigning values to any variable.

 

Maybe this example helps to better understanding:

 

data _null_;
infile datalines;
input;
put _infile_;
datalines;
a v f
1 3454 34543
a 35 354
;
run;

Esteemed Advisor
Esteemed Advisor
Posts: 7,203

Re: Data _Null_

Infile reads a line from the datafile.  The code needs to do this to know how many observations (_n_) its on.  It doesn't need to create any variables and increment the _n_ for the check later on.  Normally you would have an input statement which reads data and puts it into variables, but as your not saving the output dataset, nor using it in anyway other than to only output the first 50 rows of data, then its not needed.

 

Respected Advisor
Posts: 4,973

Re: Data _Null_

The purpose of the program is to dump 50 lines of the incoming data file to get a sense of what the data looks like.

 

_INFILE_ is a copy of the latest line from the incoming data file.

 

INPUT is necessary (even if no variables are being input) to update _INFILE_, allowing it to move from line line of data to the next.  Without INPUT, the program would remain stuck on the first line of data from the incoming file.

Ask a Question
Discussion stats
  • 3 replies
  • 265 views
  • 0 likes
  • 4 in conversation