|
The rules of conversion, that is, SAS expressions must have the same type of data, either a character or numeric. When mixed data types were coded, SAS automatically executes the appropriate type conversion and issues a message on the SAS log as "Character values have been converted to numeric" (or vice versa). It is commonly occurs on the assignment and the IF statement. In the following example, TAX is a character and COST is a numeric variable which causes the message to be printed on SAS log.
|
data test2;
set test1;
tax=cost;
cost=7*tax+15;
if tax=cost then delete;
run;
NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
33:9
NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
34:12 35:8
|
|
Sometimes we are aware of the different data types in our expression and because SAS does it for us, it is so convenient to forget about the conversion. Generally, I tend to clean up my SAS log for other users or auditors to look at it. Auditors, specifically, ask you whether or not the NOTE on the SAS log was an error. To avoid explaining why the message shows up on the SAS log, I always write out the conversion.
The following assignment statement converts the numeric value of COST to a character string place into variable TAX. I use PUT function and specify a numeric format as my second argument. In this case I have found that BESTn. is the safest, because It provides the highest number of significant digits as well as I do not have to guess the decimal digits.
|
data test1;
set test1;
tax = put(cost,best6.);
run;
|
|
Note: The length of the character variable should not less than the length specified in the format, otherwise, you may lose some digits. The standard result is right-justified.
|
|