Handling Mix Record Types; use of single trailing @

Consider extract of the external file as shown below;

SASBuddy Presenting....

First ever FREE Mobile App on SAS Concepts.

SAS Guide

Download it from Playstore Now!!!"

External File: sales.txt

1 USA 10JUL10 $1500

2 INDIA 10/08/10 1,200

Here we can observe that date and sale fields are having different informats in row one and two. To process this type of records we need some processing to be done on the input date and sale fields; however as soon as input statement executes input line pointer gets moved to next line of raw data file.

To cope up with this issue we can make use of Single trailing @.

Code snippet is below,

SAS Code

data temp;

infile "D:\sales.txt";

input id country:$3. @;

if country eq 'USA' then

input date:date7. sale:dollar7.;

else

input date:ddmmyy8. sale:comma7.;

run;

proc print data = temp;

title;

run;

*note that above code has been compiled on SAS 9.1 platform

In code above whenever SAS encounters ‘@’ it holds the pointer position of output dataset record. Works on conditional 'if' processing depending on the input variables and then inputs the remaining variables DATE and SALE. So in short single '@' is used to hold the input line pointer for single iteration.

Following is the output of the code above.

Output:

19:02 Thursday, October 22, 2009 37

Obs id country date sale

1 1 USA 18453 1500

2 2 IND 18484 1200