SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Raw Data in Fixed Fields
Using Formatted Input


The +n Pointer Control

The +n is a relative pointer control that moves the input pointer forward to a column number relative to the current position. The + advances the pointer n columns.

     input +n variable informat.;
In order to count correctly, it is important to understand just where the column pointer control is located after each data value is read. Let's look at an example.

Suppose you want to read the data from Empdata in the following order: LastName, FirstName, Salary, JobTitle. Like the @n pointer control, the default column location for the +n pointer control is column 1. Because the values for LastName begin in column 1, a column pointer control is not needed.

     input LastName $7.

V---+----10---+----20---+---
EVANS   DONNY 112 29,996.63 
HELMS   LISA  105 18,567.23 
HIGGINS JOHN  111 25,309.00 


With formatted input, the column pointer control moves to the first column after the field just read. In this example, after LastName is read, the pointer moves to column 8.

1---+--V-10---+----20---+---
EVANS   DONNY 112 29,996.63 
HELMS   LISA  105 18,567.23 
HIGGINS JOHN  111 25,309.00 


To start reading FirstName, beginning in column 9, you move the column pointer control ahead 1 column with +1.

     input LastName $7. +1 FirstName $5.

1---+---V10---+----20---+---
EVANS   DONNY 112 29,996.63 
HELMS   LISA  105 18,567.23 
HIGGINS JOHN  111 25,309.00 


After reading FirstName, the column pointer moves to column 14. Now you want to skip over the values for JobTitle and read the values for Salary, which begin in column 19. So you move the column pointer ahead 5 columns from column 14.

     input LastName $7. +1 FirstName $5. +5 Salary comma9.

 

                     12345
1---+----10---V---V20---+---
EVANS   DONNY 112 29,996.63 
HELMS   LISA  105 18,567.23 
HIGGINS JOHN  111 25,309.00 


The last field to be read contains the values for JobTitle. You can use the @n column pointer control to return to column 15.

     input LastName $7. +1 FirstName $5. +5 Salary comma9.
           @15 JobTitle 3.;

1---+----10---V----20---+---
EVANS   DONNY 112 29,996.63 
HELMS   LISA  105 18,567.23 
HIGGINS JOHN  111 25,309.00 


The $7., $5. , comma9. and 3., informats are explained later in this lesson.

Note: You can use the notation +(-n) to move the +n pointer control backwards. See the section on column pointer controls in SAS Language Reference: Dictionary for information on the +(-n) notation.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement