Hello,
I am preparing for Base SAS Certification , and need to know basic logic behind the following below question.
Given the text file COLORS.TXT:
----+----1----+----2----+----
RED ORANGE YELLOW GREEN
BLUE INDIGO PURPLE VIOLET
CYAN WHITE FUCSIA BLACK
GRAY BROWN PINK MAGENTA
The following SAS program is submitted:
data WORK.COLORS;
infile 'COLORS.TXT';
input @1 Var1 $ @8 Var2 $ @;
input @1 Var3 $ @8 Var4 $ @;
run;
What is the output of the program and why. kindly give the logic behind the program output.
Many thanks in advance
regards
Ved
Yes, but in an earlier response you said " is that means in above code @ prevents second input statement to being read and results in repeatition of values of var1 and var2 for var3 and var4 ??".
My answer is no! Think about the two input statements.
input @1 Var1 $ @8 Var2 $ @;
@1 will read Var1 from col1, then @8 will move the pointer to col8 and input Var2. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step
Then:
input @1 Var3 $ @8 Var4 $ @;
will move the pointer back to col1 and read Var3, then the @8 will cause the pointer to input Var4 from col8. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step. There aren't any more instructions, thus it is irrelevant as the program will then move to the next iteration.
Did you try running the program and looking at the output?
The key is the last @ in the first input. Look at the documentation for INPUT.
Yes, i have runned the code and result it showing me the repeatition of the values of var1 and var2 for var3 and var4 respectively.As per 9.2 documentation @ : (trailing @) prevents SAS from automatically reading a new data record into the input buffer when a new INPUT statement is executed within the same iteration of the DATA step.
is that means in above code @ prevents second input statement to being read and results in repeatition of values of var1 and var2 for var3 and var4 ??
Please correct if i am wrong.
thanks in advance.
rgds
ved
You're wrong, other than your explanation of the trailing blank. Provide a different explanation of your code. Would help if you explain what the @1 does.
I don't disagree with your explanation of the first trailing @. I was suggesting that you explain what the @1 and @8 do, and why the second trailing @ is irrelevant.
Yes, but in an earlier response you said " is that means in above code @ prevents second input statement to being read and results in repeatition of values of var1 and var2 for var3 and var4 ??".
My answer is no! Think about the two input statements.
input @1 Var1 $ @8 Var2 $ @;
@1 will read Var1 from col1, then @8 will move the pointer to col8 and input Var2. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step
Then:
input @1 Var3 $ @8 Var4 $ @;
will move the pointer back to col1 and read Var3, then the @8 will cause the pointer to input Var4 from col8. Finally, the @ will cause the pointer to not move to the next record until either the next instruction or the next iteration of the data step. There aren't any more instructions, thus it is irrelevant as the program will then move to the next iteration.
And a 2nd key is to look where the second input statement is pointing. The @, at the end of the second input statement is superfluous, but doesn't hurt anything.
But run the code and carefully compare the input file with the file that the data step creates.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.