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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.