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

I am trying to output a report that fits the row height to the row contents. I have a variable description in the first column and then descriptive statistics in the following columns. Some of the variable names are long enough that the text wraps. If I specify the cellheight the rows with wrapped text just cut off at the line break. If I don't specify cellheight, there is a ton of white space around each row which makes it hard to fit everything into a single table. My question is, is there a way to have a row that is a single line in height for some rows, but allows for two lines of text in other rows?

 

Thanks!

 

ods pdf file="C:\Report.pdf" uniform notoc;
ods escapechar='^';
ods layout start;
ods region x=0.00in y=1.10in width=8.00in height=9.00in;
proc report data=dataset 
	style(report)=[cellspacing=0 outputwidth=100pct width=100pct]
 	style(header)=[vjust=top font_weight=bold]
 	style(column)=[just=center];
 column printchar ("N (%) or median (IQR)" printvar1);
 define printchar / display "Variable" order=data style(column)={cellwidth=2.14in just=l};
 define printvar1 / display "Class 1" style(column)={cellwidth=1.17in just=c};
 compute printchar;
	if find(printchar,"^S={")>0 then call define(_row_,'style', 'style=[bordertopcolor=white bordertopwidth=0]');
 endcomp;
run; 
ods layout end;
ods pdf close; ods html; 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi, Unfortunately, I get this error when trying to open the PDF:

pdf_err.png

However, this example illustrates my experience with PDF:

diff_height.png

As you can see, the height varies based on the cell width. If the contents fit in the space, the row is one size and if the contents do not fit in the width, then the height increases. I used very simple data just to illustrate the example:

data try_height;
  length newvar $50;
  set sashelp.class;
  where age le 13;
  if sex = 'M' then newvar=catx('~',name, sex, age, 'Twas brillig and the slithy toves');
  else if sex = 'F' then newvar=catx('~',substr(name,1,1),sex,age);
run;

ods pdf file='c:\temp\try_height.pdf';
proc report data=try_height;
column newvar name sex age;
title '1) default widths';
run;

proc report data=try_height;
column newvar name sex age;
title '2) change width changes height';
define newvar / display style(column)={width=1in};
run;
ods pdf close;

 

It almost sounds like you're doing a demographic report. I have several examples of that kind of report in my paper, Creating Complex reports, which you can find here. https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/173-2008.pdf the example I'm thinking of is Complex 1, starting on page 9.

 

Hope this helps,

Cynthia

 

 

View solution in original post

6 REPLIES 6
Cynthia_sas
SAS Super FREQ

Hi:

  Without data, no one can test your code or understand what you're explaining. Typically, with PROC REPORT and ODS, ODS already tries to fit the row height to the cell contents. PDF is a paged destination, so factors like margins, font size, variable or string width all come into play in determining both cell width and cell height. Also, your COMPUTE block is confusing to me. It looks like the character variable already contains an old style ODS ESCAPECHAR control string which may be adversely impacting the output.

 

  I am also not clear on why you're using ODS LAYOUT and ODS REGION in your code. If all you have is one report table, I don't see the need for using ODS REGION as you show.

 

Cynthia

ColeG
Obsidian | Level 7

Hi Cynthia,

 

I'm sure you can appreciate that I can't just include data and since I don't know what's causing this I can't think of a good way to just try it out with a SAS help dataset. I have attached a file with screenshots showing a portion of the output to highlight what I'm referring to with the excessive white space between rows when I don't define cellheight.

 

You write that "ODS tries to fit the row height to the cell contents" but that's not what I'm experiencing--i.e., if I don't define cellheight my rows are too tall for 90% of the rows; if I do define cellheight then the few rows that need to be taller get cut off. My question is if there is some option that I'm missing that can help me.

 

The COMPUTE block is to include a border around variable groups. For instance, a binary variable like "% Male" would only take up one row, but a categorical variable like "Education" would need to have the header ("Highest level of education completed") and then the categories (No high school degree, high school degree or GED, etc.). That COMPUTE block removes the border between the categories but keeps it around the variable group.

 

Finally, I included reference to the fact that I am using ODS layout and regions in case that's a factor. I did not include all my extraneous code (table title, footers, page numbers, or the second page) because I felt that would make the code longer without providing additional relevant details.

Cynthia_sas
SAS Super FREQ

Hi, Unfortunately, I get this error when trying to open the PDF:

pdf_err.png

However, this example illustrates my experience with PDF:

diff_height.png

As you can see, the height varies based on the cell width. If the contents fit in the space, the row is one size and if the contents do not fit in the width, then the height increases. I used very simple data just to illustrate the example:

data try_height;
  length newvar $50;
  set sashelp.class;
  where age le 13;
  if sex = 'M' then newvar=catx('~',name, sex, age, 'Twas brillig and the slithy toves');
  else if sex = 'F' then newvar=catx('~',substr(name,1,1),sex,age);
run;

ods pdf file='c:\temp\try_height.pdf';
proc report data=try_height;
column newvar name sex age;
title '1) default widths';
run;

proc report data=try_height;
column newvar name sex age;
title '2) change width changes height';
define newvar / display style(column)={width=1in};
run;
ods pdf close;

 

It almost sounds like you're doing a demographic report. I have several examples of that kind of report in my paper, Creating Complex reports, which you can find here. https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/173-2008.pdf the example I'm thinking of is Complex 1, starting on page 9.

 

Hope this helps,

Cynthia

 

 

ColeG
Obsidian | Level 7

Hi Cynthia,

 

Yes that worked! Well, it got me about 90% of the way there but it's much closer to what I wanted. I have always used cellwidth= but in your code you have width= --can you explain the difference? When I use width= the text turns blue which it hadn't with cellwidth.

 

Thanks! And sorry my screenshots didn't work, I thought it would help illustrate but guess you didn't need it.

Cynthia_sas
SAS Super FREQ
Hi:
The original style attribute was "cellwidth", but with version 9.2 (I think, the developers added more attributes to include attributes that were familiar from their usage in CSS.) At that point, width was added and cellwidth became the allowed alias to allow legacy code to run. I could have used either attribute. When I write new code, I tend to use WIDTH. If I am running older code I'll allow CELLWIDTH to stay, since it is an alias.

Cynthia
ballardw
Super User

When I see you PDF the second example is showing something like

 

This row of text in the

cell displays okay

   

    value

 

    value

 

    value

 

indicating that the "bad is associated with the space between VALUES that are hidden inside a single cell..

I'm going to say at this time code with no data isn't terribly helpful to sometimes when the behavior is apparently data related.

It might help to provide dummy data (since you are apparently concerned about values) that mimics your data structure and variable names with values like XXXXX and YYYY or Rocky and Bullwinkle for anything sensitive.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 7110 views
  • 0 likes
  • 3 in conversation