SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
Converting Data with Functions

 
Now that you know the general form of the PUT function, you can rewrite the assignment statement in your DATA step to explicitly convert the numeric values of Site to character values.

To perform this conversion, write the PUT function by specifying Site as the source. Because Site has a length of 2, you choose 2. as the numeric format. After you add this PUT function to the assignment statement, the DATA step creates the new data set that contains Assignment.

     data hrd.newtemp;
        set hrd.temp;
        Assignment=put(site,2.)||'/'||department;
     run;

SAS Data Set Hrd.Newtemp
Overtime Job Contact Department Site BirthDate Assignment
4 Word processing Word Processor DP 26 7054 26/DP
. Filing, administrative duties Admin. Asst. PURH 57 5757 57/PURH


Notice that no conversion messages appear in the SAS log when using the PUT function.


SAS Log
13    data hrd.newtemp;
14    set hrd.temp;
15    Assignment=put(site,2.)||'/'||department;
16    run;

NOTE: The data set Hrd.Newtemp has 40 observations
      and 19 variables.
NOTE: The DATA statement used 0.71 seconds.


Matching the Data Type

Remember that the format specified in the PUT function must match the data type of the source.

PUT(source,format)

So, to do an explicit numeric-to-character data conversion, you specify a numeric source and a numeric format. The form of the PUT function is very similar to the form of the INPUT function.

PUT(source,format)

INPUT(source,informat)

Note that the PUT function requires a format, whereas the INPUT function requires an informat. To remember which function requires a format versus an informat, note that the INPUT function requires the informat.


|next


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

Terms of Use & Legal Information | Privacy Statement