Reputation: 778
I have the following program, but don't understand what @
symbol in the end of the INPUT lines does:
data colors;
input @1 Var1 $ @8 Var2 $ @;
input @1 Var3 $ @8 Var4 $ @;
datalines;
RED ORANGE YELLOW GREEN
BLUE INDIGO PURPLE VIOLET
CYAN WHOTE FICSIA BLACK
GRAY BROWN PINK MAGENTA
run;
proc print data=colors;
run;
Output produced without @
in the end of the INPUT line is different from the ouput with @
.
Can you please clarify what does @
in the end of the 2nd and 3rd INPUT lines do?
Upvotes: 2
Views: 10026
Reputation: 63424
@
at the end of an input
statement means, do not advance the line pointer after semicolon. @@
means, do not advance the line pointer after the run statement either.
Normally an input statement has an implicit advance the line pointer one after semicolon. So:
data want;
input a b;
datalines;
1 2 3 4
5 6 7 8
run;
proc print data=want;
run;
Will return
1 2
5 6
If you want to read 3 4
into another line, then, you might do something like:
data want;
input a b @;
output;
input a b;
datalines;
1 2 3 4
5 6 7 8
run;
proc print data=want;
run;
Which gives
1 2
3 4
5 6
7 8
Similarly you could simply write
data want;
input a b @@;
datalines;
1 2 3 4
5 6 7 8
run;
proc print data=want;
run;
To get the same result - @@
would hold the line pointer even across the run statement. (It still would advance once it hit the end of the line.)
Upvotes: 4
Reputation: 119
In Summary: I think you probably don't want the trailing @ in this case. The Input statements do not seem fitting for the data you are reading. With the trailing @, you are reading the same data into var1 and var3, and the same data into var2 and var4, because it is reading the same line twice. Either way, you are not reading in what the data appears to be. You would be better off with:
input Var1 $ Var2 $ @;
input Var3 $ Var4 $;
Or, more simply:
input Var1 $ Var2 $ Var3 $ Var4 $;
Official details from the SAS support site, annotated: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146292.htm
Using Line-Hold Specifiers
Line-hold specifiers keep the pointer on the current input record when
- a data record is read by more than one INPUT statement (trailing @) Use a single trailing @ to allow the next INPUT statement to read from the same record.
Normally, each INPUT statement in a DATA step reads a new data record into the input buffer. When you use a trailing @, the following occurs:
- The pointer position does not change.
- No new record is read into the input buffer.
- The next INPUT statement for the same iteration of the DATA step continues to read the same record rather than a new one.
SAS releases a record held by a trailing @ when
- a null INPUT statement executes: input;
- an INPUT statement without a trailing @ executes
- the next iteration of the DATA step begins.
Upvotes: 2