SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
Converting Data with Functions


Explicit Character-to-Numeric Conversion

The INPUT function converts character data values to numeric values. To learn how to use this function, let's examine one of the data set modifications needed for Hrd.Temp. As mentioned earlier, you need to calculate employee salaries by multiplying the character variable PayRate by the numeric variable Hours.


SAS Data Set Hrd.Temp
City State Zip Phone BeginDate EndDate PayRate Days Hours
CARY NC 27513 6224549 14567 14621 10 11 88
CARY NC 27513 6223251 14524 14565 8 25 200
CHAPEL HILL NC 27514 9974749 14570 14608 40 26 208
RALEIGH NC 27612 6970450 14516 14527 15 10 80


To calculate salaries, you write the following DATA step. It creates a new data set, Hrd.Newtemp, to contain the original data plus the new variable Salary.
     data hrd.newtemp;
        set hrd.temp;
        Salary=payrate*hours;
     run;

However, you know that submitting this DATA step would cause an automatic character-to-numeric conversion because the character variable PayRate is used in a numeric context. You can explicitly convert the character values of PayRate to numeric by using the INPUT function.


General form, INPUT function:
INPUT (source,informat)

where

  • source indicates the character variable, constant, or expression to be converted to a numeric value
  • a numeric informat must also be specified, as in this example:
    input(payrate,2.)
    


When choosing the informat, be sure to select a numeric informat that can read the form of the values.


Character Value Informat
2115233 7.
2,115,233 COMMA9.


Example

Here's an example of the INPUT function:

     Test=input(saletest,comma9.);

The function uses the numeric informat COMMA9. to read the values of the character variable SaleTest. Then the resulting numeric values are stored in the variable Test.

|next


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

Terms of Use & Legal Information | Privacy Statement