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
|
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- |
General form, INPUT function:
where
|
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
|
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.