SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Variable-Length Records
Reading Variable-Length Fields


Creating a Varying Size Length-Variable

Now let's think about how to give instructions for reading the values for Name. First, you need to create a length-variable that contains the length of each raw data value for Name.

Let's call the length-variable namelen. As you can see, the value of namelen varies.

Raw Data File Phonedat
1---+----10---+----20
1802JOHNSON2123
1803BARKER2142
1804EDMUNDSON2325
1805RIVERS2543
1806MASON2646



>
>
>
>
>



namelen= 7
namelen= 6
namelen= 9
namelen= 6
namelen= 5

     data perm.phones; 
        infile phondat length=reclen;
        input ID 4. @;
        namelen=??????
But remember, each record contains only three fields and the width of both ID and PhoneExt is 4 in every record. So, the values for ID and PhoneExt take up only 8 spaces in each record. Therefore, the value of namelen is the length of each record (reclen) minus the length of ID and PhoneExt(8).

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

back||next


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

Terms of Use & Legal Information | Privacy Statement