Data visualization with SAS programming

Set Width of Tabulate

Accepted Solution Solved
Reply
Super Contributor
Posts: 443
Accepted Solution

Set Width of Tabulate

In SAS 9.2 is there a way to set the width of a tabulate block?  E.g

PROC TABULATE missing FORMAT=COMMA8. style=[width=800];

I found a few references for how to set the width of a cell.

PROC TABULATE data=one f=10.2 S=[foreground=black just=c cellwidth=200];


Accepted Solutions
Solution
‎03-16-2015 03:52 PM
Grand Advisor
Posts: 9,748

Re: Set Width of Tabulate

ods graphics on / width=8in; You may want to also investigate whether to use the options Scale=on/off or scalemarkers=on/off as the font and markers may change with the graph sizes.

View solution in original post


All Replies
Grand Advisor
Posts: 9,748

Re: Set Width of Tabulate

You can set in a class , classlev, var or keyword as an option but there are interactions that may not be obvious hence  the style_precedence option.

The Style elements referenced in the online help under the Tabulate Tables syntax can be used in the other statements that describe variables.

I would also recommend always using a measurement unit points, in, cm or something.

such as:

<from the middle of one of my tabulate calls

   class grade /order=unformatted ;

   classlev grade /style={width=.5in};

   var Enrollment enroll7 EnrollK1 /style={width=1.75in};

Super Contributor
Posts: 443

Re: Set Width of Tabulate

Does this format the size of a cell or the size of the entire table?

Grand Advisor
Posts: 9,748

Re: Set Width of Tabulate

Generally which ever gets applied sets the width of a column. You run into issues when you try to specify the width for a column header that is across several other variables or classlevels though, especially if the sum of the sublements doesn't match the header. If you have multiple variables as row headers the one at the top takes precedence and you might get some interesting messages in the logs about conflicts that don't make sense immediately.

Row=float may be helpful in some cases as a table option.

SAS Super FREQ
Posts: 8,647

Re: Set Width of Tabulate

HI:

  try this code and see if that helps. Placement of the WIDTH= option will impact either a particular set of cells of the whole table.

Cynthia



ods html file='c:\temp\tabwidth.html';

proc tabulate data=sashelp.class style={width=2in};
title '1) width on TABULATE stmt';
var height weight;
class sex;
table sex,
      min*height max*weight;
run;


proc tabulate data=sashelp.class ;
title '2) width on TABLE stmt';
var height weight;
class sex;
table sex,
      min*height max*weight /
      style={width=8in};
run;


proc tabulate data=sashelp.class  ;
title '3) width on VAR stmt';
var height weight /style={width=2in};
class sex;
table sex,
      min*height max*weight;
run;

proc tabulate data=sashelp.class  ;
title '4) width on CLASS stmt';
var height weight ;
class sex / style={width=2in};
table sex,
      min*height max*weight;
run;

ods html close;

Super Contributor
Posts: 443

Re: Set Width of Tabulate

I found that when I run:

proc tabulate data=sashelp.class style={width=2in};
title '1) width on TABULATE stmt';
var height weight;
class sex;
table sex,
min*height max*weight;
run;

On a set of data with x columns and a set of data with x+3 columns that the table width varied considerably.  It seems that the setting is based on column width not table width.

Super Contributor
Posts: 443

Re: Set Width of Tabulate

I figured out a trick.  I made an html table of 8 inches on the outside of the SAS tabulate block.  I used

proc tabulate data=sashelp.class style={width=8in};
title '1) width on TABULATE stmt';
var height weight;
class sex;
table sex,
      min*height max*weight;
run;

Because the tabulate block is contained in the HTML table it cannot expand beyond 8 inches.

Currently working out a few bugs with it but it should work.

Super Contributor
Posts: 443

Re: Set Width of Tabulate

I have a sgpanel that I use with the tabulate statement.  Is there a way to format the width of the sgpanel as well?  Sometimes the panel doesn’t take up all of the 8 inches I would like it to always take up all 8 inches.

Solution
‎03-16-2015 03:52 PM
Grand Advisor
Posts: 9,748

Re: Set Width of Tabulate

ods graphics on / width=8in; You may want to also investigate whether to use the options Scale=on/off or scalemarkers=on/off as the font and markers may change with the graph sizes.

Super Contributor
Posts: 443

Re: Set Width of Tabulate

Works great.

Super Contributor
Posts: 443

Re: Set Width of Tabulate

I’m running into a scenario where I have an all statement on the left that I want to take up 8 inches of the tabulate block and a number on the right that I want to take up one inch. Is there a way to assign a length to the all block?  It seems that to add a width I need to show the variable.


The below is an example of the all statement on the left.


proc tabulate data=sashelp.class style={width=9in};

var height weight ;

table all='Total',

      min = ' '*height max = ' '*weight;

run;

Grand Advisor
Posts: 9,748

Re: Set Width of Tabulate

     min = ' '*height max = ' '*weight

      / box={style=[width=8in]};

run;

Super Contributor
Posts: 443

Re: Set Width of Tabulate

Box works for the first column only, I was able to use it to solve 2/3 of my use cases.

I have a case where I have two dynamic columns.   Where I do not want to show a blank for the column heading. 

proc tabulate data=sashelp.class;

title '5) width on CLASS stmt';

var height weight ;

class sex age / style={width=2in};

table sex*age,

      min*height max*weight / row=constant;

run;

The above works if I wanted to show the column heading.  However when I take the column heading out.  Like the below.

proc tabulate data=sashelp.class;

title '5) width on CLASS stmt';

var height weight ;

class sex age / style={width=2in};

table sex=' '*age=' ',

      min*height max*weight / row=constant;

run;

The width of two inches is removed.  I added row=constant because the description is that it causes the column width to be in effect even when there is no title, however it doesn't seem to do the trick.

Grand Advisor
Posts: 9,748

Re: Set Width of Tabulate

Columns basically only get one width (within each level of sub heading if you have nesting. So only the first one sets it  Since you are not showing the CLASS variable but the values then use CLASSLEV If I understand what your last example is doing:

proc tabulate data=sashelp.class;

title '5) width on CLASS stmt';
var height weight ;
class sex age / ;
classlev sex age /style={width=2in};
table sex=' '*age=' ',

      min*height max*weight / row=constant;

run;

Occasional Contributor
Posts: 6

Re: Set Width of Tabulate

I use a statement in pretty much every table to set this very parameter.

in the TABLE statement, I use the option STYLE={OUTPUTWIDTH=100%}

This makes the table the width of the page.

If I want a little extra space into the margins I use 105%, not sure how much higher it goes though.

For smaller tables sometimes I'll reduce that to 70-80%

Post a Question
Discussion Stats
  • 14 replies
  • 722 views
  • 6 likes
  • 4 in conversation