SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Free-Format Data
Modifying List Input


Reading Values That Contain Embedded Blanks

The ampersand (&) modifier enables you to read character values that contain single embedded blanks. The & indicates that a character value that is being read with list input may have one or more single embedded blanks. The value is read until two or more consecutive blanks are encountered. The & modifier precedes a specified informat if one is used.

     input Rank City & . . .

In the raw data file shown below, each value of City is followed by two consecutive blanks. There are two ways that you can use list input to read the values of City.


Using the & Modifier with a LENGTH Statement

As shown below, you can use a LENGTH statement to define the length of City, and then add an & modifier to the INPUT statement to indicate that the values contain embedded blanks.

     data perm.cityrank;
        infile topten;
        length City $ 12;
        input Rank city &  
     

Raw Data File Topten
1---+----10---+----20---+--
 1 NEW YORK  7,262,700 
 2 LOS ANGELES  3,259,340 
 3 CHICAGO  3,009,530 
 4 HOUSTON  1,728,910 
 5 PHILADELPHIA  1,642,900 
 6 DETROIT  1,086,220 
 7 SAN DIEGO  1,015,190 
 8 DALLAS  1,003,520 
 9 SAN ANTONIO  914,350 
10 PHOENIX  894,070 


Using the & Modifier with an Informat

You can also read the values for City with the & modifier followed by the $w. informat, which reads standard character values, as shown below. When you do this, the w value in the informat determines the variable's length and should accommodate the longest value.

     data perm.cityrank;
        infile topten;
        input Rank City & $12.  
     

Raw Data File Topten
1---+----10---+----20---+--
 1 NEW YORK  7,262,700 
 2 LOS ANGELES  3,259,340 
 3 CHICAGO  3,009,530 
 4 HOUSTON  1,728,910 
 5 PHILADELPHIA  1,642,900 
 6 DETROIT  1,086,220 
 7 SAN DIEGO  1,015,190 
 8 DALLAS  1,003,520 
 9 SAN ANTONIO  914,350 
10 PHOENIX  894,070 


Caution: Remember that two consecutive blanks are required delimiters when using the & modifier. You cannot use another delimiter to indicate the end of the field.


back||next


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

Terms of Use & Legal Information | Privacy Statement