Converting a Numeric Variable to a Character Variable
This is an example of how to change a numeric variable, ID, to character variable.
This example uses PUT function to convert numeric data to character data. The PUT function writes values with a specified format. It takes two arguments: the name of the numeric variable and a SAS format or user-defined format for writing the data.
char_id = put(id, 7.) ;
drop id ;
rename char_id=id ;
Below are a few examples of data conversions using the PUT function:
| oldvar | put function | newvar |
|---|---|---|
| 303 (8) | newvar=put(oldvar, 3.); | 303 (3) |
| 32000 (8) | newvar=put(oldvar, dollar7.); | $32,000 (7) |
| 366 (8) | newvar=put(oldvar, date9.); | 01jan1961 (9) |