SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Transforming Data with SAS Functions
Converting Data with Functions


Automatic Numeric-to-Character Conversion

The automatic conversion of numeric data to character data is very similar to character-to-numeric conversion. Numeric data values are converted to character whenever they are used in a character context.

For example, the numeric values of the variable Site are converted to character if you

  • assign the numeric value to a previously defined character variable, such as the character variable SiteCode
     SiteCode=site;

  • use the numeric value with an operator that requires a character value, such as the concatenation operator
     SiteCode=site||department;

  • specify the numeric value in a function that requires character arguments, such as the TRIM function.
     Region=trim(site);

Numeric-to-character conversion also causes a message to be written to the SAS log indicating that the conversion has occurred.


SAS Log
4        data hrd.newtemp;
5        set hrd.temp;
6        SiteCode=site||department;
7        run;

---> NOTE: Numeric values have been converted
           to character values at the
           places given by: (Line):(Column).

11:13
NOTE: The data set Hrd.Newtemp has 40 observations
      and 19 variables.
NOTE: The data statement used 1.06 seconds.


But remember, it's best not to rely on automatic conversion. When you know that numeric data must be converted to character data, perform an explict conversion by including a PUT function in your SAS program. We look at the PUT function in the next section.


|next


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

Terms of Use & Legal Information | Privacy Statement