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. SAS uses 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 that 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).
Log 4.1 Automatic Variable Type Conversions (partial SAS log)
44 data _null_;
45 x= 3626885;
46 length y $ 4;
47 y=x;
48 put y;
49 run;
NOTE: Numeric values have been converted to character
values at the places given by: (Line):(Column).
47:6
36E5
50 data _null_;
51 x1= 3626885;
52 length y1 $ 1;
53 y1=x1;
54 xs=0.000005;
55 length ys $ 1;
56 ys=xs;
57 put y1= ys=;
58 run;
NOTE: Numeric values have been converted to character
values at the places given by: (Line):(Column).
53:7 56:7
NOTE: Invalid character data, x1=3626885.00 , at line 53 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 may be shifted by the "BEST" format.
59 proc printto; run;
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.
Aligning Variable Values in SAS Output
In SAS output, numeric variables are right-aligned and character values are left-aligned.
You can further control their alignment by using a format.
However, in SAS LISTING output, when you assign a character value in an assignment
statement, SAS stores the value as it appears in the statement and does not perform any
alignment. Output 4.1 on page 44 illustrates the character value alignment produced by
the following program:
ods listing;
options nodate;
data aircode;
input city $ 1-13 WAC 15-17;
Aligning Variable Values in SAS Output 43
length airport $ 30;
if city='San Francisco' then airport='SFO';
else if city='Paris' then airport='CDG';
else if city='New York' then airport='JFK';
else if city='Moscow' then airport='MOW';
else if city='Melbourne' then airport=' MEB';
datalines;
San Francisco 67
Paris 427
New York 67
Moscow 770
Melbourne 802
;
proc print data=aircode;
run;
ods listing close;
This example produces the following LISTING output:
Output 4.1 Character Variable Alignment in SAS Listing Output
In HTML output, when you assign a character value in an assignment statement, SAS
ignores the white space and left-aligns the characters as usual. The same example above
produces the following output in HTML:
Output 4.2 Character Variable Alignment in SAS HTML Output
44 Chapter 4 SAS Variables

Get SAS 9.4 Language Reference, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.