BookmarkSubscribeRSS Feed
kranikai_2
Calcite | Level 5

Hello,

Just to learn the basics, I'm experimenting with combinations of different options of infile and input statemets, and sometimes the results are not quite those I would suppose. For example:

My data, koe.dat, contains only thoe two rows:

aa bb cc dd

gg hh ii mm

With column input,

data koe;

     infile '/users/kranikai/data/koe.dat';

     input yks $ 1-2 kaks $ 4-5 kolme $ 7-8 nelj $ 10-11 @@;

run;

I run into difficulties: there seems to be an infinite loop. At least the program never ends.

On the other hand, list input version of the same data step,

data koe;

     infile '/users/kranikai/data/koe.dat';

     input yks $  kaks $  kolme $  nelj $  @@;

run;

works perfectly, and produces a set with two observations.

What's actually happening in both instances?

Of course, to read my data, I do not need @@. However, I'd really like to know how it works exactly, with different input styles and different infile options.

2 REPLIES 2
yaswanthj
Calcite | Level 5

Hi..

Please go through this doc http://www2.sas.com/proceedings/sugi29/253-29.pdf.

you will idea about input statement and input statement options...

Thanks,

FriedEgg
SAS Employee

@@ holds the input record for the next input statement across iterations of the data step.  Your first example goes into a infinite loop because it will never move past the first input records as defined with column style input.  This detail is loosely explained in the INPUT Statement documentation under the section about pointer control.  With the relative pointer input style (you are using list style in your second example) SAS will move the pointer upon subsequent calls of the input statement to read the next line, and ultimately reach the end of you data file.  With you example data, it is also worth noting that there is no need to use the double trailing @ line hold specifier as your lines all contain only one set of data each.

try adding something like the following to better show yourself what is happening.

if _n_ gt 1 then put _n_ _infile_;

input (yks kaks kolme nelj) ($) @@;

put _infile_;

cards;

aa bb cc dd ww xx yy

gg hh ii mm zz

;

first data step iteration:

read first line (aa bb cc dd ww xx yy zz) and store in the _infile_ variable, assign first four columns, space delimited to listed variables and output record.  behind the scenes, hold file cursor at end of input for nelj variable.

second data step interation:

when you use column style input you reset the curos position to 1 and reread the line as above and repeat to infinity.

when you use list style input you continue reading from stored cursor position assigning variables values until the end of a input record is reach and another is retrieved.  variables continue to be assigned across input records until the variables are all filled, or the end of the file is encountered.  if the end of file was not encountered, we would store the current input record and cursor position for the next data step record and repeat this process.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 730 views
  • 0 likes
  • 3 in conversation