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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.