BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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];

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

14 REPLIES 14
ballardw
Super User

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};

DavidPhillips2
Rhodochrosite | Level 12

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

ballardw
Super User

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.

Cynthia_sas
SAS Super FREQ

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;

DavidPhillips2
Rhodochrosite | Level 12

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.

DavidPhillips2
Rhodochrosite | Level 12

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.

DavidPhillips2
Rhodochrosite | Level 12

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.

ballardw
Super User

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.

DavidPhillips2
Rhodochrosite | Level 12

Works great.

DavidPhillips2
Rhodochrosite | Level 12

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;

ballardw
Super User

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

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

run;

DavidPhillips2
Rhodochrosite | Level 12

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.

ballardw
Super User

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;

Brent_PLNU
Calcite | Level 5

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%

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 6878 views
  • 7 likes
  • 4 in conversation