BookmarkSubscribeRSS Feed
TreeFrog
Calcite | Level 5
Yo ODS-ers

Is there a sneaky way I could set a minimum cellheight in proc report, using ods pdf?

Setting the cellheight value on a style definition on the proc report statement seems to force this height regardless of the content of the cell. I want all cells in my report to be at least this height, and when they need to be higher because of the content they contain, they should go ahead and be higher.

This mainly relates to the names of groups in the left hand column of my report, so the text wraps and makes the cells higher by default (which is good). When the group name is very short, the consequence is the row is not very high, which looks a bit squashed because the majority of my group names are 2 or 3 lines of text high.

Thanks

TF
7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
As far as I know, when you use CELLHEIGHT and CELLWIDTH (or HEIGHT and WIDTH in SAS 9.2) attributes for ODS, you are setting the height or width of the cell -- telling ODS that you want it to use YOUR setting instead of the setting that it calculates, based on the font, the text in the cell, the cellpadding, etc. So this is more of an absolute width or height that you set, instead of a minimum.

You are right that when you use CELLHEIGHT in a style definition (or in a STYLE= override) that it "sets" the height regardless of the content of the cell. I would not necessarily call this "forcing" the height, but I can see how you would regard it that way.

It might seem counter-intuitive, but if you use CELLWIDTH, you can cause ODS to wrap text in cells by setting a smaller cellwidth than ODS needs for the text. When the text in a cell wraps, the cell must get higher as a result. Consider the program at the end of this post. Report #2 wraps the long group variable value, while Report #3 shows the increased cellheight, but there is no text wrapping. Report #1 shows the default behavior.

cynthia
[pre]
** Make some test data;
data prdsale;
set sashelp.prdsale;
short = substr(country,1,1);
long = catt(region, '~', division, '~',prodtype,'~abcdefghijklmnopqrstuvwxyz');
if division = 'CONSUMER' and region = 'EAST' and
country in ('CANADA', 'GERMANY') and
product in ('BED','CHAIR');
run;

ods pdf file='c:\temp\cellwidth.pdf';
proc report data=prdsale nowd;
title '1) Default cellwidth and cellheight';
column short long product actual predict;
define short / group;
define long / group;
define product / group;
define actual / sum;
define predict / sum;
break after short / summarize;
run;

proc report data=prdsale nowd;
title '2) Changing cellwidth ONLY';
column short long product actual predict;
define short / group;
define long / group
style(header)={cellwidth=1.5in}
style(column)={cellwidth=1.5in};
define product / group;
define actual / sum;
define predict / sum;
break after short / summarize;
run;

proc report data=prdsale nowd;
title '3) Changing cellheight ONLY -- does NOT change CELLWIDTH';
column short long product actual predict;
define short / group;
define long / group
style(header)={cellheight=1.5in}
style(column)={cellheight=1.5in};
define product / group;
define actual / sum;
define predict / sum;
break after short / summarize;
run;

ods pdf close;
[/pre]
TreeFrog
Calcite | Level 5
Thanks for your quick response Cynthia (do you ever sleep?!)

You're right when you say it's an absolute, rather than a minimum, height that is set with cellheight=.

I can see where you're going with cellwidth to make wrapping occur, but I don't want my cells any less wide because I'm pressed for horizontal space already!

I wonder whether I can put in a carriage return character at the end of some of my group names -- would that cause ODS PDF to make the cell taller? Or pad out the group name with characters that will cause a wrap but style them so they can't be seen... Any thoughts on such "hacks"?

Thanks again

TF
Cynthia_sas
SAS Super FREQ
Hi:
I'm not sure what you mean by "hacks". Inserting a line feed character into a text string is entirely possible when you use ODS ESCAPECHAR and the n character. It's not a hack, it's a supported feature. For example, if ODS ESCAPECHAR is set to '~' then ~n is a line feed and ~2n is 2 line feeds (or a double space). (In SAS 9.2, the newer syntax convention would be ~{newline}, but ~n still works in 9.2).

If you are pressed for horizontal space, you have some other alternatives in addition to inserting a line feed:
1) change the orientation to landscape and/or change the margin options for PDF to make the margins smaller
2) make the font sizes smaller
3) reduce the default cellpadding (white space around the letters in the cell)

For more information on inserting a line feed character into a text string using ODS ESCAPECHAR, refer to the ODS documentation or these papers (written for SAS 9.1.3 and SAS 9.2):
http://www2.sas.com/proceedings/forum2007/099-2007.pdf
http://www.nesug.org/Proceedings/nesug07/cc/cc18.pdf
http://www.nesug.org/proceedings/nesug08/np/np10.pdf
http://www2.sas.com/proceedings/forum2007/144-2007.pdf
http://www2.sas.com/proceedings/sugi31/227-31.pdf

cynthia
TreeFrog
Calcite | Level 5
Hi Cynthia

Thanks for your suggestions. When I said 'hacks' I was referring to the (possible) practice of adding more characters to the end of my string and styling them so they can't be seen. The linefeed is something I'm familiar with, and not a hack 🐵

I'm going to try the linefeed and/or checking the length of the string and conditionally "call define"-ing a taller cell height for shorter length strings, next time I'm on site. I'll try and remember to report back.

Thanks again
Tree Frog
Cynthia_sas
SAS Super FREQ
Hi:
I guess I still don't understand why you'd alter the cellheight for -shorter- strings??? To make them the same as LONGER strings??? You'd have to check the documentation to see -- I believe there are some style attributes that you cannot change in a CALL DEFINE statement. If you CAN change cellheight, you would not probably be able to change it for a _COL_ choice, but, instead might have to try to change it for the _ROW_ -- since, it doesn't make sense to have one cell in a row a different height from the other cells.

As for your idea to add characters to the end of a string, you can simply add spaces to the end of your string and then to have the spaces respected, you would need to use the style attribute ASIS=ON -- which causes leading and trailing spaces to be respected. And, the ESCAPECHAR+UNDERSCORE is the equivalent of a NON-BREAKING SPACE (somewhat equivalent to   entity in HTML).

So if ESCAPECHAR is '^', then Asia^_^_^_^_^_ is 5 non-breaking spaces appended to the value for REGION.

cynthia
TreeFrog
Calcite | Level 5
Hi again

I achieved what I was after by altering the cellheight in a call define for the row, based on the length of the value of the grouping variable. I realise that without the benefit of a diagram, it must have been hard to figure out what I was after. Certainly it was the whole row I wanted to heighten in these cases.

The reason I wanted to alter the cellheight (hence the height of the whole row) for shorter strings was a "requirement": the client saw the initial report in which most group names were long and hence these names wrapped and made their rows higher, and said something like, "that's good, but gee, those few rows in there where the names are short sure look funny because they're not as tall as all the others. Could we make them a bit higher so it all looks a bit more uniform?"

Thanks for your help Cynthia, I've learnt quite a bit about what's possible in this thread.

Tree Frog
TreeFrog
Calcite | Level 5
null Removed accidental duplicate posting


Message was edited by: Tree Frog

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
  • 7 replies
  • 4979 views
  • 0 likes
  • 2 in conversation