SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

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


Number of Records Per Observation

It's important to note that there must be the same number of records in the external file for each observation being created.

For example, suppose that there are only two records for the second member. However, the INPUT statement is set up to read three records.


     data perm.members;
        infile memdata;
        input Fname $ Lname $ /
        Address $ 1-20 /
        City & $10. State $ Zip $;
1---+----10---+----20
LEE ATHNOS  
1215 RAINTREE CIRCLE 
PHOENIX  AZ 85044  
HEIDIE BAKER  
1751 DIEHL ROAD  
VIENNA  VA 22124  
MYRON BARKER 
131 DONERAIL DRIVE 
ATLANTA  GA 30363 
JOYCE BENEFIT 
85 MAPLE AVENUE 
MENLO PARK  CA 94025 


The second member's name and address are read and assigned to corresponding variables. Then the input pointer advances to the next record, as directed by the INPUT statement, and the third member's name is read as a value for City.

Still looking for a value for State and Zip, the input pointer advances to the next record and reads the values for the member's address.

PROC PRINT output for this data set illustrates the problem.


Obs Fname Lname Address City State Zip
1 LEE BEDWAN 1215 RAINTREE CIRCLE PHOENIX AZ 85044
2 HEIDIE BAKER 1751 DIEHL ROAD MYRON BARK 131 DONERAIL
3 ATLANTA GA JOYCE BENEFIT 85 MAPLE A MENLO PARK


So, before you write the INPUT statement, make sure the raw data file contains the same number of records for each observation.
 1---+----10---+----20
1 LEE ATHNOS  
21215 RAINTREE CIRCLE 
3PHOENIX  AZ 85044  
1HEIDIE BAKER  
21751 DIEHL ROAD  
3VIENNA  VA 22124  
1MYRON BARKER 
2131 DONERAIL DRIVE 
3ATLANTA  GA 30363 
1JOYCE BENEFIT 
285 MAPLE AVENUE 
3MENLO PARK  CA 94025 


Note: The SAS System provides tools for working with raw data files that contain missing values. See the section on handling missing values in Step-by-Step Programming with Base SAS Software or the section on the SAS Language Reference: Dictionary for more information.


back||next


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

Terms of Use & Legal Information | Privacy Statement