Thursday, August 6, 2009

processing of data step

@ vs @@ (line hold specifiers)

when the end of input statement is reached the pointer moves to t he next line .also the input buffer is replaced with new line of data that follows.SAS executes the following statements using the values in the pdv(program data vector).
There are situations when reading rest of data in a line depends on data read so far.in other words if there is a need to execute a second input statement to read rest of data from input buffer.
The trailing @ forces sas to hold the pointer on the current position of data in the input buffer .also causes sas to execute another input statement before the contents of input buffer are replaced .
Let us see the following example---

data data1;
infile cards;
input city :$ @;
do quarter =1 to 4 ;
input rain @;
output;
end;
cards;
delhi 50 45 55 67

;


run;

output---
` Obs city quarter rain

1 delhi 1 50
2 delhi 2 45
3 delhi 3 55
4 delhi 4 67

The first use of @ holds the dataline to read further values from the dataline using a second input statement.the second @ hold the dataline to read further values of ‘rain’ form same dataline .
Noteall this is done in a single data step;

@@
The trailing @@ causes the input statement to be executed repeatedly for the same dataline and each time the input statement is executed an iteration of data step also takes place.
One situation is when we want to read multiple records from same line of data.

Data multiple;
Infile cards;
Input name$ city$ @@;
Cards;
Smith nj Scott ca tiger del
;
Run;

Output—

Obs name city

1 Smith nj
2 Scott ca
3 tiger del

Two values at a time are read using data from input buffer.sas reaches the end of data step.pointer is hold at the same dataline even after the dat step is executed and the values are still there in the input buffer.
Here @ would not work because the next iteration of data step would have set the values to missing.
So the difference between @ @@ is that while trailing @ hold the line for the same iteration of the data step,trailing @@ hold the dataline even for the next iteration as well.

Send link to --

TopBlogDir.blogspot.com button Education Blog Directory Academic,  Learning & Educational Blogs - Blog Catalog Blog Directory SEO Court Directory myblog Visit blogadda.com to discover Indian blogs Add to Technorati Favorites Subscribe with Bloglines DigNow.net

Join My Community at MyBloglog!

Free Web Directory - Add Your Link
The Little Web Directory
Monster Directory A List Sites