08-09-2017 02:20 AM
So it really depends on what they mean by "after the third observation has been read".
First I would use the term observations to refer to records in a SAS dataset, but this program is reading lines from a raw data file.
Second do they mean after the third line is read and before the assignment statement executes? or after the assignment statement has executed?
The value of COUNT when the third line is read by the INPUT statement will be 130 since the value that was output at the end of the second iteration of the data step is still there since it is being retain. You get to 130 by adding the 10 and 20 to the initial value of 100.
Now what the result will be after the assignment statement executes depends on how the source file is formatted. If the third line has at least three spaces on it (something that CANNOT be determined from the photograph you posted) then TENS will be missing and COUNT will stay at 130.
But if the third line has less than three characters on it then SAS will go to the next line to find two characters and so TENS will be 4 and the COUNT total with 134.
Try it yourself.
filename dat temp; data _null_; input str $3. ; file dat ; len=lengthn(str); put @2 str $varying2. len ; cards; 10 20 40 50 ; run; data test; infile dat ; input tens 2-3 ; retain count 100; count + tens; put (_n_ tens count) (=) ; run; data _null_; input str $char3. ; file dat ; len=lengthn(str); put str $char3. ; cards; 10 20 40 50 ; run; data test; infile dat ; input tens 2-3 ; retain count 100; count + tens; put (_n_ tens count) (=) ; run;