I am solving this problem but have got stuck.Can anyone help me out.
Thanks .
Please include the question directly in the post. Users will not download attachments.
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;
Hey Thankyou so much Tom for a detailed explanation ..
@rajvir Please mark Tom's solution as the correct answer (not this post!).
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.