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



sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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