SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
Converting Data with Functions

 
Explicit Numeric-to-Character Conversion

Using the PUT function, you can explicitly convert numeric data values to character data values.

Let's use this function to complete one of the modifications needed for the data set Hrd.Temp. Suppose you are asked to create a new character variable named Assignment that concatenates the values of the numeric variable Site and the character variable Department. The new variable values must contain the value of Site followed by a slash and then the value of Department, for example 26/DP.


SAS Data Set Hrd.Temp
Overtime Job Contact Department Site
4 Word processing Word Processor DP 26
. Filing, administrative duties Admin. Asst. PURH 57
. Organizational dev. specialist Consultant PERS 34
. Bookkeeping, word processing Bookkeeper Asst. BK 57


To concatenate the values, you write an assignment statement that contains the concatenation operator, ||, to indicate that Site should be concatenated with a slash and then concatenated with Department. Note that the slash appears in quotation marks. All character constants must be specified in quotation marks.
     data hrd.newtemp;
        set hrd.temp;
        Assignment=site||'/'||department;
     run;

You know that submitting this DATA step will cause SAS software to automatically convert the numeric values of Site to character because Site is used in a character context. The variable Site appears with the concatenation operator, which requires character values. To explicitly convert the numeric values of Site to character values, you must add the PUT function to your assignment statement.


General form, PUT function:
PUT (source,format)

where

  • source indicates the numeric variable, constant, or expression to be converted to a character value
  • a format matching the data type of the source must also be specified, as in this example: 
    put(site,2.)
    


Because you are listing a numeric variable as the source, you must specify a numeric format.


|next


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

Terms of Use & Legal Information | Privacy Statement