SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating a Single Observation from Multiple Records
Reading Multiple Records in Any Order


Using the #n Line Pointer Control

Take a closer look at using the #n line pointer control in the following example.

The raw data file Patdata contains patient information from a small group of general surgeons.

The first three records contain a patient's name, address, city, state, and ZIP code. The fourth record contains the patient's ID number followed by the name of the primary physician.

Raw Data File Patdata
 1---+----10---+----20---
1ALEX BEDWAN 
2609 WILTON MEADOW DRIVE 
3GARNER NC 27529 
4XM034 FLOYD 
 ALISON BEYER 
 8521 HOLLY SPRINGS ROAD 
 APEX NC 27502 
 XF124 LAWSON 


Suppose you want to read each patient's information in the following order:
  1. ID number (ID)
  2. first name (Fname)
  3. last name (Lname)
  4. address (Address)
  5. city (City)
  6. state (State)
  7. ZIP (Zip)
  8. doctor (Doctor)

  • To read the values for ID in the 4th record, specify #4 before naming the variable and defining its attributes.


     data perm.patients;
        infile patdata;
        input #4 ID $5.
1---+----10---+----20---
ALEX BEDWAN 
609 WILTON MEADOW DRIVE 
GARNER NC 27529 
XM034 FLOYD 


  • To read the values for Fname and Lname in the first record, specify #1 before naming the variables and defining their attributes.


     data perm.patients;9  
        infile patdata;
        input #4 ID $5.
              #1 Fname $ Lname $ 
1---+----10---+----20---
ALEX BEDWAN 
609 WILTON MEADOW DRIVE 
GARNER NC 27529 
XM034 FLOYD 


  • Use the #n line pointer control to position the input pointer on the second record and read the value for Address.


     data perm.patients;
        infile patdata;
        input #4 ID $5.
              #1 Fname $ Lname $
              #2 Address $23.
1---+----10---+----20---
ALEX BEDWAN 
609 WILTON MEADOW DRIVE 
GARNER NC 27529 
XM034 FLOYD 

  • Now direct the input pointer to the third record and read the values for City, State, and Zip respectively.

Note: In this raw data file, the values for City contain eight characters or less and do not contain embedded blanks. So, you can use standard list input to read these values.


     data perm.patients;
        infile patdata;
        input #4 ID $5.
              #1 Fname $ Lname $ 
              #2 Address $23.
              #3 City $ State $ Zip $
1---+----10---+----20---
ALEX BEDWAN 
609 WILTON MEADOW DRIVE 
GARNER NC 27529 
XM034 FLOYD 

  • Now you need to move the input pointer down to the fourth record to read the values for Doctor, which begin in column 7. Don't forget to add a semicolon at the end of the INPUT statement. A RUN statement completes the program.


     data perm.patients;
        infile patdata;
        input #4 ID $5.
              #1 Fname $ Lname $ 
              #2 Address $23.
              #3 City $ State $ Zip $
              #4 @7 Doctor $6.;
     run;
1---+----10---+----20---
ALEX BEDWAN 
609 WILTON MEADOW DRIVE 
GARNER NC 27529 
XM034 FLOYD 

back||next


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

Terms of Use & Legal Information | Privacy Statement