Reputation: 28391
The following code will give a TYPE count for each MAKE group
proc report data=sashelp.cars nowd;
column make type;
define make / group;
define type / across;
run;
How can a format be applied to the across columns created?
Upvotes: 1
Views: 11604
Reputation: 28391
In the below code displaying a count of the ACROSS variable is assumed. However, it can be made explicit by using a comma, in the COLUMN statement after the ACROSS variable. The N column can then be formatted in a DEFINE statement.
proc report data=sashelp.cars nowd;
column make type,n;
define make / group;
define type / across;
define n / '' format=comma10.1;
run;
When there will be multiple across columns, formatting the columns uniquely can be accomplished in a COMPUTE block. In order to review how the columns will look, use an OUT= statement on the PROC REPORT line to generate a data set. Including a MISSING= option can replace the missing dots with zeros. Art Carpenter's book is an excellent guide to Proc Report...and where I got this tip.
Options missing=0;
proc report data=sashelp.cars nowd out=work.report;
column make type,n;
define make / group;
define type / across;
define n / '';
compute n;
call define('_c4_','format','dollar10.');
endcomp;
run;
Anytime a reference to an absolute column (ex. ____c4____) is used there is the potential for an error when that column does not exist. Creating a user format and using PRELOADFMT on the DEFINE statement for that ACROSS variable will force all format values to appear and guarantee that ____c4____ exists. See this question for more info.
options missing=.;
Proc format;
value $type
'Hybrid'='Hybrid' 'SUV'='SUV' 'Sedan'='Sedan'
'Sports'='Sports' 'Truck'='Truck' 'Wagon'='Wagon';
Run;
Proc Report data=sashelp.cars(where=(make='Buick')) nowd;
column make type,n;
define make / group;
define type / across format=$type. preloadfmt;
define n / '';
compute n;
call define('_c4_','format','dollar10.');
endcomp;
run;
One further edit, that a co-worker showed me, by "blanking" all labels on the define statements, the empty space below the across variables can be removed. In this example, since the group variable (MAKE) now has no label, it needs it's label in the column statement.
options missing=.;
Proc format;
value $type
'Hybrid'='Hybrid' 'SUV'='SUV' 'Sedan'='Sedan'
'Sports'='Sports' 'Truck'='Truck' 'Wagon'='Wagon';
Run;
proc report data=sashelp.cars(where=(make='Buick')) nowd;
column ('Make' make) type,n;
define make / '' group;
define type / '' across format=$type. preloadfmt;
define n / '';
compute n;
call define('_c4_','format','dollar10.');
endcomp;
run;
Upvotes: 1