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!
If you want such control of the report I think you should use PROC TABULATE and RTM.
Or do you consider about proc sql ?
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.
Are you sure?
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.
It doesn't show 2 decimal places. Is that what you think it should do?
That specific value rounds to 36.20 but doesn't display the 0 due to the general behavior of BEST format.
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.
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.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.