Hello
In this proc tabulate table I want to order by column PCTSUM
The code is not working.
How can I order output by PCTSUM?
proc tabulate data=sashelp.cars;
class Make/ORDER=PCTSUM;
var Invoice;
table Make='',Invoice=''*(n='Cars sold' PCTN='%Cars sold' SUM='Sum sales' PCTSUM='PCT SUM sales')/box='Brand';
run;
You can't order by PCTSUM, but as @andreas_lds notes you can order by data (i.e. in order of the data set). So you could
proc summary data=sashelp.cars;
class make;
var invoice;
output out=need (where=(_type_=1)) mean=invoice sum=invtotal;
run;
proc sort;by descending invtotal;run;
proc tabulate data=need order=data;
class make;
var invoice;
freq _freq_;
table Make='',Invoice=''*(n='Cars sold' PCTN='%Cars sold' SUM='Sum sales' PCTSUM='PCT SUM sales')/box='Brand';
run;
Have a look at the documentation: the option "order" is defined as
ORDER=DATA | FORMATTED | FREQ | UNFORMATTED
So there is no way to specify pctsum as sort-order.
You can't order by PCTSUM, but as @andreas_lds notes you can order by data (i.e. in order of the data set). So you could
proc summary data=sashelp.cars;
class make;
var invoice;
output out=need (where=(_type_=1)) mean=invoice sum=invtotal;
run;
proc sort;by descending invtotal;run;
proc tabulate data=need order=data;
class make;
var invoice;
freq _freq_;
table Make='',Invoice=''*(n='Cars sold' PCTN='%Cars sold' SUM='Sum sales' PCTSUM='PCT SUM sales')/box='Brand';
run;
Or in a modification of @mkeintz use one pass through proc tabulate to create an output data set then a data step for some modification and then sort. You may use proc tabulate but with pre-calculated statistics you need to be careful not to ask for pcts or sums again. Or use proc report list output.
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 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: