Transforming Data with SAS Functions | |
Converting Data with Functions |
Introduction to Converting Data
Suppose you are asked to complete a number of modifications to the data set
Hrd.Temp. The first modification is to create a new variable
that contains the salary of temporary employees. Examining the data set,
you realize that one of the variables needed to calculate salaries is 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 |
data hrd.newtemp; set hrd.temp; Salary=payrate*hours; run; In such cases, you should use the INPUT function before attempting the calculation. The INPUT function converts character data values to numeric. The PUT function converts numeric data values to character. Both functions are discussed in this section.
What happens if you skip the INPUT or the PUT function when converting data?
SAS software will detect the mismatched variables and try an automatic
character-to-numeric or numeric-to-character conversion. However, this process
won't always work. Suppose each value of It is always best to include INPUT and PUT functions in your programs when conversions occur. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.