Help using Base SAS procedures

maxdecs=2 not sufficient to avoid .00 values

Reply
Occasional Contributor
Posts: 8

maxdecs=2 not sufficient to avoid .00 values

Hi,

I have a quite simple beginners question:

Lets consider the following data set:

data temporary;

Input ID Number Name $ Age;

Datalines;

1 214 Hans 20

2 215 Peter 22

3 210 Gustav 24

4 209 Elvira 55

5 208 Ivonne 60

6 206 Claire 62

;

run;

I created a age class variable like this:

data temporary;

set temporary;

if age<42 then ageclass=1;

else ageclass=0;

run;

(please do not post a comment if this is a good idea or not, this is not my question).

Now I want to analyze it in the following way:

proc means data=temporary maxdecs=2;

var age;

class ageclass;

run;

In the results e.g. in the mean column there are values such as 59.00 and 22.00. It is correct that I want to have two digits, so e.g. 3.61 makes sense for me. However, I do not like that sas displayes two .00 where it is not necessary. So for the values with .00 I would like to have a simple rounding, so that simply 59 and 22 are displayed, but I do not want the 3.61 to be rounded.

How can I achieve this?

Thanks a lot for your help!

Respected Advisor
Posts: 3,799

Re: maxdecs=2 not sufficient to avoid .00 values

If you want such control of the report I think you should use PROC TABULATE and RTM.

Super User
Posts: 10,020

Re: maxdecs=2 not sufficient to avoid .00 values

Or do you consider about proc sql ?

Super User
Posts: 11,343

Re: maxdecs=2 not sufficient to avoid .00 values

Send the output to a data set and use another procedure to display the results. In that procedure associate a format like BEST5.2; If the value is integer it will not display decimals, if there are 2 or more decimals it will only display a maximum of 2.

If only one decimal that is all that would display so if you expect 3.20 to appear it won't.

Respected Advisor
Posts: 3,799

Re: maxdecs=2 not sufficient to avoid .00 values

Are you sure?

Super User
Posts: 11,343

Re: maxdecs=2 not sufficient to avoid .00 values

Posted in reply to data_null__

With 9.3 and running a few variations of the number of decimals in the value of x in this program:

data _null_;                                                                                                                           

   x= 36.199;                                                                                                                          

   put x= best5.2;                                                                                                                     

run;         

Those were the results displayed in the log.                                                                                                                         

Respected Advisor
Posts: 3,799

Re: maxdecs=2 not sufficient to avoid .00 values

It doesn't show 2 decimal places.  Is that what you think it should do?

data _null_;
  
x= 36.199;
  
put x= best5.2 x=best5.;
  
run;  

37         data _null_;
38            x= 36.199;
39            put x= best5.2 x=best5.;
40            run;

x=36.2 x=36.2
Super User
Posts: 11,343

Re: maxdecs=2 not sufficient to avoid .00 values

Posted in reply to data_null__

That specific value rounds to 36.20 but doesn't display the 0 due to the general behavior of BEST format.

Respected Advisor
Posts: 3,799

Re: maxdecs=2 not sufficient to avoid .00 values

The point I am try to get you to acknowledge and understand is that BESTw. does not have D.  If it is specified it is ignored.

Super User
Posts: 11,343

Re: maxdecs=2 not sufficient to avoid .00 values

Posted in reply to data_null__

I hate when I try something and accidentally pick an example that doesn't pick up what I wanted, which I would have gotten wth best6. Thanks for reminder.

Occasional Contributor
Posts: 19

Re: maxdecs=2 not sufficient to avoid .00 values

I feel it is better to use proc tabulate like this..

Proc tabulate data=temporary;

class ageclass;

var age;

table ageclass, age*(n mean*f=bestd6.2 ); run;

Using the formar bestd6.2

This should work. !

Ask a Question
Discussion stats
  • 10 replies
  • 267 views
  • 6 likes
  • 5 in conversation