Formatted output from PROC MEANS might differ from expectations because of ODS template attributes


The formatted output of the MEANS procedure can differ from expectations because the ODS template for the procedure contains an option that causes default attributes, such as format width, to be used instead of those attributes explicitly specified in numeric formats associated with or applied to variables. For example, numeric format output can be wider (have more characters) than expected when the default format width is greater than the specified width. Similarly, the output can be narrower when the default width is less than the specified width. This issue affects only ODS output (printed output to any destination or an ODS output data set) from PROC MEANS and does not affect internal numeric representation or calculation of results. Output data sets created through ODS will have formats with default attributes applied to the variables. Output data sets created by the traditional OUTPUT statement are not similarly affected.

The following example illustrates this behavior:

data foo;
   input c x;
   datalines;
          123    1
         1233    2
         1234    3
        12345    4
        12346    5
       123456    6
      1234567    7
      1234568    8
     12345678    9
     12345679   10
;
run;

ods output summary=odsout;
proc means data=foo sum nway;
   class c;
   var x;
   format c dollar10.;
   output out=meansout sum=Sum;
run;

proc print data=odsout;
run;
proc print data=meansout;
run;

proc contents data=odsout;
run;
proc contents data=meansout;
run;

Here, because of the USE_FORMAT_DEFAULTS option in the procedure's ODS template, the width of 10 specified for the DOLLAR format in the FORMAT statement is overridden by the format's default width of 6. In the printed output of PROC MEANS, this causes the values of variable C to be limited to 6 characters, and in the ODS output data set, variable C has a format of DOLLAR6.

If you do not desire default formats to be applied to the output data set, then create your output data set using the OUTPUT statement instead of ODS OUTPUT. If you do not desire ODS output from PROC MEANS to use default format attributes, then you can modify the Base.Summary ODS table template as shown below.

proc template;
   edit base.summary;
      use_format_defaults=off;
   end;
run;

See the Output section below for a comparison of the ODS output, the OUTPUT statement output, and the modified ODS output with the template changes.


Output

Default ODS output

     c    NObs           x_Sum

  $123      1                1
$1,233      1                2
$1,234      1                3
$12345      1                4
$12346      1                5
123456      1                6
1.23E6      1                7
1.23E6      1                8
1.23E7      1                9
1.23E7      1               10

 

Default OUTPUT statement output

         c    _TYPE_    _FREQ_    Sum

      $123       1         1        1
    $1,233       1         1        2
    $1,234       1         1        3
   $12,345       1         1        4
   $12,346       1         1        5
  $123,456       1         1        6
$1,234,567       1         1        7
$1,234,568       1         1        8
 $12345678       1         1        9
 $12345679       1         1       10

 

Modified ODS output with Template changes

         c    NObs           x_Sum

      $123      1                1
    $1,233      1                2
    $1,234      1                3
   $12,345      1                4
   $12,346      1                5
  $123,456      1                6
$1,234,567      1                7
$1,234,568      1                8
 $12345678      1                9
 $12345679      1               10