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
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;
@braam wrote:
Seems that I have no choice but to use the DEFINE statements.
Yes. Is this a problem for you?
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.
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;
@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 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.