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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.