SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

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 PayRate. To complete the calculation, you need to convert PayRate from character to numeric.


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.


Potential Problems of Omitting INPUT or PUT

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 PayRate began with a dollar sign ($). When SAS software tries to automatically convert the value of PayRate to numeric values, the dollar sign blocks the process. The value cannot be converted into a numeric value. Similar problems can occur with automatic numeric-to-character conversion.

It is always best to include INPUT and PUT functions in your programs when conversions occur.


|next


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

Terms of Use & Legal Information | Privacy Statement