BookmarkSubscribeRSS Feed
braam
Quartz | Level 8

Thanks to the PROC REPORT, I can easily check my data. But can I change the format of MEAN of all variables listed? I know I can do that if I define each variable under PROC REPORT. But like shown in the code, I want to give a list (e.g., length, weight,...).

 

 

 

	proc report data= sashelp.cars missing;
		column type  length,(n mean) weight,(n mean);
		define type / group; run;

 

  Length Weight
Type n mean n mean
Hybrid 3 168.33333 3 2490.6667
SUV 60 188.13333 60 4444.4333
Sedan 262 187.10305 262 3399.0649
Sports 49 173.28571 49 3295.6939
Truck 24 207.70833 24 4250.75
Wagon 30 182.43333 30 3438.8

 

What I would like to see is just mean values that are rounded up:

  Length Weight
Type n mean n mean
Hybrid 3 168 3 2491
SUV 60 188 60 4444
Sedan 262 187 262 3399
Sports 49 173 49 3296
Truck 24 208 24 4251
Wagon 30 182 30 3439
7 REPLIES 7
PaigeMiller
Diamond | Level 26

What I would like to see is just mean values that are rounded up:

 

Rounded off is easy, rounded up would have to be done in a data step.

 

proc report data= sashelp.cars missing;
		column type  length,(n mean) weight,(n mean);
		define type / group; 
		define length / format=8.0;
		define weight / format=8.0;
		run; 

 

--
Paige Miller
braam
Quartz | Level 8
Thanks for your answer. Seems that I have no choice but to use the DEFINE statements.
PaigeMiller
Diamond | Level 26

@braam wrote:
Seems that I have no choice but to use the DEFINE statements.

Yes. Is this a problem for you?

--
Paige Miller
braam
Quartz | Level 8
Oh no. It's OK.

At times, I have several variables, for which I would like to see N and mean. I was wondering if there is a way to format all MEAN statistics at once.
PaigeMiller
Diamond | Level 26

Originally, you said:

Thanks to the PROC REPORT, I can easily check my data.

 

If the goal is to check the data, rather than to create a very well formatted report for presentation, I don't know why you even care about formatting the variables. It just seems like extra work to me.

 

Now, when I am preparing PROC REPORT results for a presentation or to include in a published document, I do spend a lot of time making sure the formatting and layout etc. is exactly what I want.

--
Paige Miller
unison
Lapis Lazuli | Level 10

@braam,

As @PaigeMiller suggested, you must define format on each analysis variable.

proc report data= sashelp.cars missing;
column type  length,(n mean) weight,(n mean);
define type / group;
define length / format=8.;
define weight / format=8.;
run;

You can circumvent this by transposing all _numeric_ variables so that _name_=numeric_var and then you can define 1 analysis variable (COL1=amt):

proc sort data=sashelp.cars out=have;
by _character_;
run;

proc transpose data=have out=want(rename=(_name_=numeric_var col1=amt));
by _character_;
var _numeric_;
run;

proc report data=want;
column type numeric_var, amt,(n mean);
define type / group;
define numeric_var / across;
define amt / '' analysis format=8.;
run;

 

-unison
ballardw
Super User

@braam wrote:

Thanks to the PROC REPORT, I can easily check my data. But can I change the format of MEAN of all variables listed? I know I can do that if I define each variable under PROC REPORT. But like shown in the code, I want to give a list (e.g., length, weight,...).

 

 

 

	proc report data= sashelp.cars missing;
		column type  length,(n mean) weight,(n mean);
		define type / group; run;

 

  Length Weight
Type n mean n mean
Hybrid 3 168.33333 3 2490.6667
SUV 60 188.13333 60 4444.4333
Sedan 262 187.10305 262 3399.0649
Sports 49 173.28571 49 3295.6939
Truck 24 207.70833 24 4250.75
Wagon 30 182.43333 30 3438.8

 

What I would like to see is just mean values that are rounded up:

  Length Weight
Type n mean n mean
Hybrid 3 168 3 2491
SUV 60 188 60 4444
Sedan 262 187 262 3399
Sports 49 173 49 3296
Truck 24 208 24 4251
Wagon 30 182 30 3439

Perhaps a different procedure:

proc tabulate data=sashelp.cars;
   class type;
   var length weight;
   table type, 
         (length weight) *(n mean*f=8.)
         
   ;

run;

If you want the same statistics with the same formats applied you use parentheses to group the like variables Example: (length weight)

and then the * indicates which statistics to display. If you have multiple statistics then group them with parentheses as well.

The Mean*f= is how to  specify a format for the mean statistic. In this case up to 8 digits with no decimal component.

You can use variable lists such as

proc tabulate data=sashelp.cars;
   class type;
   var _numeric_;
   table type, 
         (_numeric_) *(n mean*f=8.)
         
   ;

run;

or

proc tabulate data=sashelp.cars;
   class type;
   var _numeric_;
   table type, 
         (enginesize-- MPG_highway) *(n mean*f=8.)
         
   ;

run;

where the -- indicates adjacent variables.

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!

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