Newsgroups: bit.listserv.sas-l
Date:         Tue, 8 Sep 1992 13:30:21 EDT
Reply-To:     "Nelson R. Pardee" <SASMAINT@SUVM.BITNET>
From:         "Nelson R. Pardee" <SASMAINT@SUVM.BITNET>
Subject:      Digits printed in PROC PRINT

About a month ago I wrote to SAS-L:
 >Without a format, PROC PRINT prints vars using BEST12.- almost!
 >  If it doesn't need 12 columns, it uses fewer.  It's nice
 >  that if the values falling on a given page are small, it uses fewer
 >  columns. I have a variable with a wide range of values- sometimes
 >  more than 12 digits, so they are printed in exponential format, which
 >  is unacceptable.  I don't want to use a format statement like
 >  format var BEST15.;
 >  since then the variable will be printed using 15 columns even if it
 >  doesn't need that many.  Any suggestions on how I can get it to not
 >  use exponential format for larger values, but still use the minimum
 >  number of columns?
 >
 >I'm running on CMS, but that shouldn't matter.
Several folks, including Phil Miller, Kernon Gives, Howard Schreier,
and Bob Snyder made suggestions. Bob's suggestion seemed to provide
the best solution using PROC FORMAT with DEFAULT=. It's right there
in the manual (well, but without an example to suggest how to use).

One note on printing with *NO* format:
you may in fact get more than 12 digits, depending on the values
of the numbers printed. See below.
 ---------------------------
1          options ls=79 nocenter;
2          *TRYING TO PRINT NUMBERS WITH MORE THAN 12 DIGITS AND RETAINING
3           THE CAPABILITY OF USING FEWER THAN 12 COLUMNS WHEN NOT NEEDED;
4
5          DATA X;              *CREATE SOME SAMPLE DATA;
6          INPUT X @@; N+1;
7           if _n_=1 then put _infile_;
8          CARDS;

10  123456789012  1234567890123  12345678901.3  123456.7890123
NOTE: SAS went to a new line when INPUT statement reached past the end of a
      line.
NOTE: The data set WORK.X has 5 observations and 2 variables.
 ------------------------------------------------------------------
11         PROC PRINT;
12          title 'print with SASs default format (which is best12.)';
13          TITLE2 'Note: prints more than 12 digits but truncates
123456.7890123';
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.

OBS                  X    N
 1               10.00    1
 2     123456789012.00    2
 3     1234567890123.0    3
 4      12345678901.30    4
 5           123456.79    5
 ------------------------------------------------------------------
15         PROC PRINT data=X(WHERE=(N^=5));
16 title'Same, except obs 123456.7890123 deleted.Only 12 digits printed';
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.

OBS               X    N
 1               10    1
 2     123456789012    2
 3     1.2345679E12    3
 4      12345678901    4
 ------------------------------------------------------------------
18        proc print data=x(where=(n=1));
19        title 'Print 2 digit number with no format';
20        title2 'Note X uses the minimum number of columns on the page';

OBS     X    N
 1     10    1
 ------------------------------------------------------------------
22         proc print data=x(where=(n=1));
23          format x best13.;
24 title 'Print 2 digit number with BEST13.';
25 title2'Note column for X occupies all 13 columns although not needed';

OBS                X    N
 1                10    1
 ------------------------------------------------------------------
31         proc format;               *Now- the solution;
32          value x (default=20) ;
 ------------------------------------------------------------------
34         proc print data=x;
35          title 'Print numbers w/special format. All digits printed';
36          format x x.;

OBS          X           N
 1                 10    1
 2       123456789012    2
 3      1234567890123    3
 4      12345678901.3    4
 5     123456.7890123    5
 ------------------------------------------------------------------
39 proc print data=x(where=(n=1));
40 title 'Print 2 digit number w/special format. Uses minimum columns';
41          format x x.;

OBS    X     N
 1     10    1
 ------------------------------------------------------------------
 --Nelson R. Pardee,  Computing Services, Syracuse University          --
 --120 Hinds Hall, Syracuse, NY 13244-1190 USA   (315)443-1079         --
 --Bitnet: SASMAINT@SUVM     Internet: SASMAINT@SUVM.ACS.SYR.EDU       --
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU