BookmarkSubscribeRSS Feed
mohitraj4u
Calcite | Level 5

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 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

2 REPLIES 2
Kurt_Bremser
Super User

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.

Reeza
Super User

@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 @. 

 

    input @1 Var1 $ @8 @Var2 $ @; <- reads var1 starting from position1, var2 from position 8 and holds the line.
    input @1 Var3 $ @8@ Var4 $ @; <- reads var3 starting from position1, var4 from position 8  and holds the line. The run allows it to move to a new line. 
 

@mohitraj4u wrote:

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 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



hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2002 views
  • 2 likes
  • 3 in conversation