SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Variable-Length Records
Reading Variable-Length Fields


Reading Variable-Length Values

The next step involves reading the values of Name and PhoneExt. Because the data is not in fixed fields or separated by delimiters, column and list input cannot be used. The $w. informat is not effective because the w value specifies only one field width. So, you need a special informat that reads fields that have varying widths.

The $VARYINGw. informat is a special SAS informat that enables you to read a character value, which has a length that differs from record to record.


General form, INPUT statement with the $VARYINGw. informat:
INPUT variable $VARYINGw. length-variable;
where
  • variable is a character variable
  • $VARYINGw. specifies the length of the variable
  • length-variable specifies a numeric variable that contains the actual width of the character field in the current record.


Raw Data File Phonedat
1---+----10---+----20
1802JOHNSON2123
1803BARKER2142
1804EDMUNDSON2325
1805RIVERS2543
1806MASON2646
1807JACKSON2049
1808LEVY2856
1809THOMAS2222


It's important to understand how the $VARYINGw. informat is different from other character informats. This informat is composed of two parts, the informat and the length variable.

         INPUT variable $VARYINGw. length-variable;

The second INPUT statement uses the $VARYINGw. informat to read the values for Name from column 5 until the length is specified by namelen. Then the values for PhoneExt are read.

     data perm.phones; 
        infile phondat length=reclen;
        input ID 4. @;
        namelen=reclen-8;
        input Name $varying10. namelen 
              PhoneExt;

back||next


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

Terms of Use & Legal Information | Privacy Statement