BookmarkSubscribeRSS Feed
NCEU
Calcite | Level 5

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!

10 REPLIES 10
data_null__
Jade | Level 19

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

Ksharp
Super User

Or do you consider about proc sql ?

ballardw
Super User

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.

data_null__
Jade | Level 19

Are you sure?

ballardw
Super User

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.                                                                                                                         

data_null__
Jade | Level 19

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
ballardw
Super User

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

data_null__
Jade | Level 19

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.

ballardw
Super User

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.

viveklanka
Fluorite | Level 6

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. !

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1135 views
  • 6 likes
  • 5 in conversation