BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I would like to ask why for 18888.88  I get 1888.88 with best. and best12. formats?

data _null_;
   num = 18888.88;
   int = 123456789012;
   dat ='28aug17'd;
   put num best12.;  /*      1888.88 */
   put num best.  ;  /*      1888.88 */
   put int best.  ;  /* 123456789012 */
   put dat best.  ;  /*        21059 */ 
run;
2 REPLIES 2
Quentin
Super User

Do you really?  I get 18888.88:

 

1    data _null_;
2       num = 18888.88;
3       int = 123456789012;
4       dat ='28aug17'd;
5       put num best12.;  /*      1888.88 */
6       put num best.  ;  /*      1888.88 */
7       put int best.  ;  /* 123456789012 */
8       put dat best.  ;  /*        21059 */
9    run;

    18888.88
    18888.88
123456789012
       21059
SASJedi
Ammonite | Level 13

The BEST. format default width is 12, so these two PUT statements:

data _null_;
   num = 18888.88;
   put num best.;
   put num best12.;
run;

will produce the same output:

    18888.88
    18888.88

Note that the entire value is expressed as a total of 12 characters (4 leading spaces, a 1, four 8s, a ., and two more 8s. for a total of 12 characters). If you specified a width other than the default (12): 

data _null_;
   num = 18888.88;
   put num best.; 
   put num best16.;
run;

the output would be different:

    18888.88
        18888.88

See how that second line now has 4 more leading spaces?

I hope this helps.

Mark

 

Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1824 views
  • 0 likes
  • 3 in conversation