SAS Variables |
If you define a numeric variable and assign the result of a character expression to it, SAS tries to convert the character result of the expression to a numeric value and to execute the statement. If the conversion is not possible, SAS prints a note to the log, assigns the numeric variable a value of missing, and sets the automatic variable _ERROR_ to 1. For a listing of the rules by which SAS automatically converts character variables to numeric variables and vice-versa, see Automatic Numeric-Character Conversion.
If you define a character variable and assign the result of a numeric expression to it, SAS tries to convert the numeric result of the expression to a character value using the BESTw. format, where w is the width of the character variable and has a maximum value of 32. SAS then tries to execute the statement. If the character variable you use is not long enough to contain a character representation of the number, SAS prints a note to the log and assigns the character variable asterisks. If the value is too small, SAS provides no error message and assigns the character variable the character zero (0).
Automatic Variable Type Conversions (partial SAS log)
1 data _null_; 2 x= 3626885; 3 length y $ 4; 4 y=x; 5 put y; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 4:6 36E5 6 data _null_; 7 x1= 3626885; 8 length y1 $ 1; 9 y1=x1; 10 xs=0.000005; 11 length ys $ 1; 12 ys=xs; 13 put y1= ys=; 14 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 9:7 12:7 NOTE: Invalid character data, x1=3626885.00 , at line 9 column 7. y1=* ys=0 x1=3626885 y1=* xs=5E-6 ys=0 _ERROR_=1 _N_=1 NOTE: At least one W.D format was too small for the number to be printed. The decimal might be shifted by the "BEST" format.In the first DATA step of the example, SAS is able to fit the value of Y into a 4-byte field by representing its value in scientific notation. In the second DATA step, SAS cannot fit the value of Y1 into a 1-byte field and displays an asterisk (*) instead.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.