Given the text file COLORS.TXT:
----+----1----+----2----+----
The following SAS program is submitted:
What will the data set WORK.COLORS contain?
Answer:
Var1 Var2 Var3 Var4
------ ------ ------ ------
RED ORANGE RED ORANGE
BLUE INDIGO BLUE INDIGO
CYAN WHITE CYAN WHITE
GRAY BROWN GRAY BROWN
The trailing @ holds the record pointer in the current line, so the second input statement re-reads positions 1 and 8; the third and fourth column of the infile are therefore never read.
@Look at the INPUT statement. You are using both @ to denote the position of where to start reading and a trailing @.
@the trailing @ keeps the pointer at the line for that data step iteration. At the next data step iteration it moves on. Check the behaviour by running the code with and without the trailing @.
@mohitraj4u wrote:
Given the text file COLORS.TXT:
----+----1----+----2----+----
RED ORANGE YELLOW GREENBLUE INDIGO PURPLE VIOLETCYAN WHITE FUCSIA BLACKGRAY BROWN PINK MAGENTAThe following SAS program is submitted:
data WORK.COLORS;infile 'COLORS.TXT';@ input @1 Var1 $ @8 Var2 $ @;@ input @1 Var3 $ @8 Var4 $ @;
run;What will the data set WORK.COLORS contain?
Answer:
Var1 Var2 Var3 Var4
------ ------ ------ ------
RED ORANGE RED ORANGE
BLUE INDIGO BLUE INDIGO
CYAN WHITE CYAN WHITE
GRAY BROWN GRAY BROWN
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.