Home Contact Us

Tech Teaser

 

Home
ASAP
SLIST Editor
Resources
Links
Tips
Tech Teaser

For those who like a challenge, have a look at the following program and see if you can find the problem(s).

It's designed to test your technical knowledge and skills, and perhaps to teach you something new.

Enjoy.

The objective is to read some data, keeping only valid records, as defined in a format. All valid records should also be counted and the total written to the log.

Should be simple.

 

/* Define valid values  */

proc format;

   value $valid

     '120'-'129', '140'-'145'  = '1';

run;

 

/* Read and keep valid records */

data valid (keep = recid);

   infile cards  missover  eof=lastrec;

   input  recid $;

   if put(recid, $valid.) = '1'

   valid_recs + 1;

return;

 

lastrec:

   put valid_recs=;

return;

 

cards;

123

130

141

;

run;

 

proc print;

run;

 

 

/* Jump to lastrec label on end of file */

/* Continue only if a valid recid */

 

/* At end of file, print count */

 

/* Three records to read, the first and third are valid */

"Expected" Output:

 

valid_recs=2

 

        The SAS System

 

         Obs    recid

          1      123

          2      141

 

 

Actual Output:

 

valid_recs=3

 

        The SAS System

 

         Obs    recid

          1      123

          2      130

          3      141

          4

 

What went wrong?

 

 

Home ] Tech Teaser Solution ]


Copyright 2007 Softscape Solutions Pty Ltd