SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading Raw Data in Fixed Fields
Using Informats


Reading Nonstandard Numeric Data

The COMMAw.d informat is used to read numeric values and remove embedded

  • blanks
  • commas
  • dashes
  • dollar signs
  • percent signs
  • right parentheses
  • left parentheses, which are converted to minus signs.


The COMMAw.d informat has three parts:

1. the informat name COMMA
2. a value that specifies the width of the field to be read, delimited by a period

w.

3. an optional value that specifies the number of implied decimal places for a value (not necessary if the value already contains decimal places).

d


In the example below, the values for Salary contain commas, which means that they are nonstandard numeric values.

The values for Salary begin in column 19, so use the @n or +n pointer control to point to column 19 and name the variable.

     data perm.empinfo;
        infile empdata;
        input @9 FirstName $5. @1 LastName $7. +7 Jobtitle 3. 
              @19 Salary

1---+----10---+---V20---+---
EVANS   DONNY 112 29,996.63 
HELMS   LISA  105 18,567.23 
HIGGINS JOHN  111 25,309.00 
LARSON  AMY   113 32,696.78 
MOORE   MARY  112 28,945.89 
POWELL  JASON 103 35,099.50 
RILEY   JUDY  111 25,309.00 


Now add the COMMAw.d informat and specify the field width. The values end in column 27, so the field width is 9 columns. Add a RUN statement to complete the DATA step.

     data perm.empinfo;
        infile empdata;
        input @9 FirstName $5. @1 LastName $7. +7 JobTitle 3. 
              @19 Salary comma9.;
     run;
                                 123456789
1---+----10---+---V20---+-V-
EVANS   DONNY 112 29,996.63 
HELMS   LISA  105 18,567.23 
HIGGINS JOHN  111 25,309.00 
LARSON  AMY   113 32,696.78 
MOORE   MARY  112 28,945.89 
POWELL  JASON 103 35,099.50 
RILEY   JUDY  111 25,309.00 


If you use PROC PRINT to display the data set, the commas are removed from the values for Salary in the resulting output.

     data perm.empinfo;
        infile empdata;
        input @9 FirstName $5. @1 LastName $7. +7 JobTitle 3.
           @19 Salary comma9.;
     run;
     proc print data=perm.empinfo;
     run;

Obs FirstName LastName JobTitle Salary
1 DONNY EVANS 112 29996.63
2 ALISA HELMS 105 18567.23
3 JOHN HIGGINS 111 25309.00
4 AMY LARSON 113 32696.78
5 MARY MOORE 112 28945.89
6 JASON POWELL 103 35099.50
7 JUDY RILEY 111 25309.00


Thus, the COMMAw.d informat does more than simply read the raw data values. It strips out special characters, such as commas, from numeric data and stores only numeric values in a SAS data set.

Hot Tip: You can use the EUROw.d informat or the EUROXw.d informat to read numeric values that contain embedded Euro symbols (E) and other special characters. The EUROw.d informat assumes that a decimal point is used as a separator between the whole number and the decimal portion. The EUROXw.d informat assumes that a comma is used as a separator between the whole number and the decimal portion.

 



back||next


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

Terms of Use & Legal Information | Privacy Statement