How do i order the row headings in proc tabulate by a format?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

How do i order the row headings in proc tabulate by a format?


Hi everyone,

I'm running the following code and the column headings are coming out in the same order as the format, but the row headings are coming out in alphabetical order.  I would like the row headings to be in the same order as the format.  Can anyone help?

proc format;

  Value $colfmt

  "New Zealand"

  "Australia"

;

run;

proc format;

   Value $catfmt

     "Good"

     "Bad"

   ;

run;

proc tabulate data=dataset;

  class country type;

  format country $colfmt. type=$catfmt.;

  table country,type;

run;


Accepted Solutions
Solution
‎06-19-2014 09:40 PM
Occasional Contributor
Posts: 9

Re: How do i order the row headings in proc tabulate by a format?

Hi R,

I did try both the preload formats and the order = option.  While they both worked with the column headings, they don't work for the row headings.

I did find a neat trick from one of the sas papers.  That is to use the order=formatted, but to put spaces in the format lables.  SAS will order according to the most spaces first.   For example:

proc format;

  Value $colfmt

  "  New Zealand"

  "Australia"

;

run;

Hope this helps someone else.

Cheers,

Celia.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,274

Re: How do i order the row headings in proc tabulate by a format?

Hi Celia,

You may want to look at the PreLoadFmt option on the class statement. Have a look at the example at

25400 - Use of PRELOADFMT with PROC TABULATE

BTW, in future if you have a SAS programming question you may want to post it within the specific support community rather than SANZOC so you get a wider audience response (until the group goes public, that is). The support communities are listed at

Cheers,

Michelle

Contributor
Posts: 34

Re: How do i order the row headings in proc tabulate by a format?

Try the ORDER= option

R

Solution
‎06-19-2014 09:40 PM
Occasional Contributor
Posts: 9

Re: How do i order the row headings in proc tabulate by a format?

Hi R,

I did try both the preload formats and the order = option.  While they both worked with the column headings, they don't work for the row headings.

I did find a neat trick from one of the sas papers.  That is to use the order=formatted, but to put spaces in the format lables.  SAS will order according to the most spaces first.   For example:

proc format;

  Value $colfmt

  "  New Zealand"

  "Australia"

;

run;

Hope this helps someone else.

Cheers,

Celia.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 376 views
  • 0 likes
  • 3 in conversation