BookmarkSubscribeRSS Feed
rajvir
Fluorite | Level 6

I am solving this problem but have got stuck.Can anyone help me out.

Thanks .

4 REPLIES 4
Reeza
Super User

Please include the question directly in the post. Users will not download attachments.  

Tom
Super User Tom
Super User

So it really depends on what they mean by "after the third observation has been read".

image.png

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;

 

 

rajvir
Fluorite | Level 6

Hey Thankyou so much  Tom for a detailed explanation ..

Reeza
Super User

@rajvir Please mark Tom's solution as the correct answer (not this post!).

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
  • 4 replies
  • 1211 views
  • 1 like
  • 3 in conversation