BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

How to display decimal places for mean median and std based on the data.

 

age

20

30

50

 

if the data say min and max for 20 and 50:

mean=33.333333333

std=15.275252317

median=30

 

How to display statistics as below:

Mean, median 1 decimal more than data. Standard deviation should be 2 decimal more than data (Data varies for each variable).

mean=33.3

std=15.27

median=30.0

 

 

 

 

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

How do you calculate these statistics?

PaigeMiller
Diamond | Level 26

You apply formats to the results to get the desired decimal places.

 

If you need something in general that figures out how many decimal places are in the original data, you'd have to write a macro that figures this out and the determines the proper formats.

--
Paige Miller
ballardw
Super User

@SASPhile wrote:

How to display decimal places for mean median and std based on the data.

 

age

20

30

50

 

if the data say min and max for 20 and 50:

mean=33.333333333

std=15.275252317

median=30

 

How to display statistics as below:

Mean, median 1 decimal more than data. Standard deviation should be 2 decimal more than data (Data varies for each variable).

mean=33.3

std=15.27

median=30.0

 


I suggest picking a reasonable value and not attempting to determine how many internal decimals are stored and adjusting from that. Many numbers can only be approximated by the binary coding and often use many more "decimal places" in internal storage than you might expect. Plus what do would you want if most of the values are integers and you have one value like 10.12345678? Do you really need 9 decimal places in that case?

 

And are displayed values at that precision actually needed? If I am talking about real estate prices will often actually have two decimal places (Unites States and values to the nearest cent). But when the mean price of something is like $266,834.281 does the extra tenth of a cent have any practical use? An argument can be made that for most purposes that anything under $100 is likely not meaningful in practical terms.

 

You can investigate the properties of a variable to find if the format has specified a typical display range but if you have lots of "best8." type formats that wouldn't help.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 2937 views
  • 0 likes
  • 4 in conversation