Hello.
I have create this code:
proc tabulate data=sashelp.cars;
class Origin DriveTrain;
table Origin * (DriveTrain all="Sub Total") all="Grand Total", all*n;
keylabel n='Number of each Drive Train';
run;
Which gives me this:
But how do I sort the all, front and rear in descending order for each drivetrain like it does in excel pivot table below:
Thanks in advance.
Try this:
proc tabulate data=sashelp.cars; class Origin; class DriveTrain/ order=freq; table Origin * (all="Sub Total" DriveTrain ) all="Grand Total", all*n; keylabel n='Number of each Drive Train'; run;
I moved the All for the Drivetrain subtotal to have the total appear a the top if you want that behavior from the "pivot" as well.
Caution: the order=freq can get tricky with nested variables in complex tables.
@SYLC wrote:
Hello.
I have create this code:
proc tabulate data=sashelp.cars;
class Origin DriveTrain;
table Origin * (DriveTrain all="Sub Total") all="Grand Total", all*n;
keylabel n='Number of each Drive Train';
run;
Which gives me this:
But how do I sort the all, front and rear in descending order for each drivetrain like it does in excel pivot table below:
Thanks in advance.
Thanks. I see what you mean by tricky. For the most part it has work but there are a few rows out of sequence.
I guess the alternative would be to create a table from scratch using the count function.
proc tabulate data=sashelp.cars;
class Origin DriveTrain /order=freq;
table Origin * (DriveTrain all="Sub Total") all="Grand Total" , all=''*n
/ Box='Origin and Drive Train';
keylabel n='Number of each Drive Train';
run;
/*Very interesting question.
Hope SAS could have an option to handle this sitation.*/
proc freq data=sashelp.cars noprint ;
table Origin*DriveTrain/out=classdata ;
run;
proc sort data=classdata;by Origin descending count;run;
data classdata;
length DriveTrain $ 100;
set classdata;
by Origin;
n+first.Origin;
DriveTrain=repeat(' ',n)||DriveTrain;
drop n;
run;
proc tabulate data=classdata format=best. ;
class Origin DriveTrain/order=data;
var count;
table Origin * (DriveTrain all="Sub Total") all="Grand Total", all*count="Number of each Drive Train"*sum="";
run;
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!
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.