BookmarkSubscribeRSS Feed
hiteshchauhan1
Obsidian | Level 7

I have a few doubts regarding "bestw." format.

 

i) What exactly is "bestw." format and how does it work in SAS?

ii) I tried googling it but i am still confused about how "bestw." work and if i want to use a specific format instead of using "bestw." then how can i found that one particular format that suits my need and the data set that i am working upon.

iii) Does using "bestw." make the code bulky/inefficient (makes the processing slow). If this is not the case  then why don't we always use "bestw." instead of any other format ? 

iv) what is the advantage of using "bestw." over any other format? or there aren't any and it's just a way to get things done when we don't know which format to use?

 

Please answer if anyone has any idea about "bestw." format. I am using SAS EG 7.1.

Thanks.

 

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

BESTw. is the standard numeric format that will try to fit the number as best as it can, using any formatting that does this. So in the code below, SAS will allocate 8 characters (best8.) to represent the number as accurate as possible with scientific/non scientific notation

 

data test;
input number;
format number best8.;
datalines;
1
1.25
1.23456
123456762
123456.29573
1234567890123
;
run;

 

 

hiteshchauhan1
Obsidian | Level 7

Do you know how can i find out which format SAS is assigning to a value while using "bestw.". for eg, zw.d format or any other format. I want that particular format and then using that format in my program instead of "bestw.".

PeterClemmensen
Tourmaline | Level 20

I'm not sure I understand this. SAS doesn't choose some pre defined format that fits the entire variable the best. It represent each number with the most accuracy given the allocated characters. 

ballardw
Super User

@hiteshchauhan1 wrote:

Do you know how can i find out which format SAS is assigning to a value while using "bestw.". for eg, zw.d format or any other format. I want that particular format and then using that format in my program instead of "bestw.".


You can find the current default format assignment by:

Running Proc Contents on the data set. This will give you all of the variables names and formats.

Opening the table containing the variable and clicking on the header. That should bring up an information box with the variable name, label if any, current format and informat.

In the SAS Explorer window right click on a table and select "View Columns" from the pop up menu. This will open a window with all the variable names, types , formats, informats, lengths, labels. If the format is blank it is the default BEST.

 

To use a different format than the default in ANY procedure use a Format statement referencing the variable and the desired format.

 

Tom
Super User Tom
Super User

FORMATs are just instructions for how to convert values into text. 

 

For most variables you don't need to worry about formats for SAS data.  SAS knows how to display character strings as text and it knows how to display numbers as text. In particular for numbers it will default to using the BEST12. format.  (I think in PROC SQL the default is BEST8. instead).  Note for date, time and datetime values you will want to attach formats because otherwise what is displayed is the raw number of days or seconds and that will be hard for humans to read.

 

The reason to use other formats is when the default doesn't work that well for the report you are making.  So you might want to use the COMMA format with large integers to make it easier for humans to see the magnitude. Or if you have non-integer values you might want to use a format with a fixed number of decimal places so that the decimal points will align in a column of numbers.  Or you might want to use a $ format with a width much shorter than the length of the variable to do a quick grouping of the values by the first few characters.

 

So the BEST format tells SAS to make figure out for each number how much precision can be fit into the number of characters you have told it to use.  So if the number is too large it will display it using scientific notation to get the maximum number of digits of precision displayed in the limited number of characters you have told it to use.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 684 views
  • 2 likes
  • 5 in conversation