Transforming Data with SAS Functions | |
Converting Data with Functions |
Now let's use the INPUT function to convert the character values of
PayRate to numeric. You begin the function by specifying
PayRate as the source. Because PayRate has a length
of 2, you choose the numeric informat 2. to read the values of the variable.
input(payrate,2.) Finally, you add the function to the assignment statement in your DATA step. data hrd.newtemp; set hrd.temp; Salary=input(payrate,2.)*hours; run;
After the DATA step is executed, the new data set (which contains the variable
|
SAS Data Set Hrd.Newtemp
City | State | Zip | Phone | BeginDate | EndDate | PayRate | Days | Hours | BirthDate | Salary |
CARY | NC | 27513 | 6224549 | 14567 | 14621 | 10 | 11 | 88 | 7054 | 880 |
CARY | NC | 27513 | 6223251 | 14524 | 14565 | 8 | 25 | 200 | 5757 | 1600 |
Notice that no conversion messages appear in the SAS log when using the INPUT function. |
SAS Log
13 data hrd.newtemp; 14 set hrd.temp; 15 Salary=input(payrate,2.)*hours; 16 run; |
The form of the INPUT function is very similar to the form of the PUT
function (which completes numeric-INPUT(source,informat) However, note that the INPUT function requires an informat, whereas the PUT function requires a format. To remember which function requires a format versus an informat, note that the INPUT function requires the informat. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.