Hi, Peter:
ODS PDF takes into account font size, font face, cell padding, cell spacing, border width, (from the style template) and number of characters in the column, if the column is text, number of total characters, including spaces and punctuation in the string. (Column headers are also taken into account and whether there are any spanning headers, because a skinny column could have a fat header...and vice versa)
If you -could- automate it, you would essentially be doing what PDF is already doing. And you'd have to do that for EVERY by group to come up with the max for all the by groups and then use that value for the cell width. My approach is way less scientific -- I picked a number that looked approximately OK, ran the program once, fiddled with the number a bit more and then that was the final number I used.
Numbers can be specified as percents, as well as in absolute inches or cm. Also, I've discovered that if I try to make the size too small, if my size conflicts with what PDF wants to set, it will not use the smaller size -- because of the algorithm.
When you say "required" cell-width, I have to ask required by whom? ODS PDF -did- calculate the required cell width for the separate by groups in the original program that was posted. The results were apparently unsatisfactory -- since each BY group is treated as a whole, the first table had a different cell width for var Y than the second table. ODS PDF did calculate the required cell width -- as PDF operated within the rules of SAS -- but the cell width that it calculated was for each BY group.
If you notice, the original code DID have the UNIFORM option for ODS PDF. The UNIFORM option at the "ODS" level does not calculate across BY groups. However, if you tried this code with the PROC PRINT UNIFORM option, it would produce the same results as the original undesired results -- with different cell widths for each BY group.
I don't know whether this behavior (treating each BY group separately) is something that could be changed. Since there's is a way to alter the cell width that ODS PDF wants to set, I suppose you could try to automate it -- but I'd probably try something easier like figuring out the number of columns, and allocating a percent to each column first. Like if there are 5 columns, make each column a cellwidth of 20%, etc, etc.
cynthia