The SAS Output Delivery System and reporting techniques

How to diguise text in ODS output

Reply
Occasional Contributor
Posts: 10

How to diguise text in ODS output

I'm trying to make a report with Proc Report and ODS.
I have 5 columns, with defined width. The text for some columns takes more space than the actual width of a column. Standard, in the output-table the text will wrap to a next line. As a consequence the height of the row will change; that is what I do'nt want! I just want to keep the width and only show the part of the text that will fit in the width.

Example:
text= "This is a long text that will not fit in a small column."
column-width= 34px;

To be shown:
|| This is a long text that will not f ||

I have tried several Style-options in Proc Report: nowrap, pretext='' posttext=''. The last combination (pre - post) does not wrap, but widens the column.

What can I do?
SAS Super FREQ
Posts: 8,739

Re: How to diguise text in ODS output

Hi:
What is your destination of interest???? ODS RTF, PDF or HTML???

The program below illustrates the difference between a simple format of $35. versus using the cellwidth style attribute. With a format, the length of the LONGVAR2 variable ($270) is not used and instead, the formatted width of $35 is used for the display of the variable value. The cellwidth approach allows the rowheight to vary, as the 270 characters of text "flow" into the cellwidth.

Thanks,
cynthia
[pre]
data longtxt;
length longvar longvar2 $270;
set sashelp.class(obs=2);
longvar = catx(' ','Twas brillig and the slithy toves.',
'Did gyre and gimble in the wabe',
'All mimsy were the borogroves',
'And the mome raths outgrabe.',
'Beware the Jabberwock my son',
'The jaws that bite, the claws that snatch.',
'Beware the jubjub bird and shun',
'the frumious Bandersnatch.');
longvar2 = longvar;
if name = 'Alfred' then name = 'Lewis';
run;

ods listing close;
ods rtf file='c:\temp\longvar.rtf' ;

proc report data=longtxt nowd;
column name height longvar longvar2;
title '1) Really LONG char var';
define name / display style(column)={just=c};
define height / display style(column)={just=c};
define longvar/ display
style(column)={cellwidth=2.5in};
define longvar2 / display
f=$35.;
run;
ods _all_ close;
title; footnote;

[/pre]
Occasional Contributor
Posts: 10

Re: How to diguise text in ODS output

Hi Cynthia,

Destination is ODS HTML.
The goal is to keep both the width as the height.
And i don't think a string-format is of any help: we use Arial as fonttype, so the actual length of a text is depending on what characters are in the text (ranging from "w" to "i" or 'l").
So actually i wanna "hide" all extra characters behind the right-border of the cell.
SAS Super FREQ
Posts: 8,739

Re: How to diguise text in ODS output

Hi:
If you use my code in ODS HTML, the simple format method does work. I don't know what you mean by "keep both the width as the height" and "hide all extra characters behind the right-border of the cell" -- by keeping the width the same as the height, I think you mean that you do NOT want the text of a long variable to flow. By "hiding all extra characters" -- I do not understand what you mean.

I know about how proportional fonts work. However, ODS calculates the cellwidth and cellheight automatically based on the destination, the font, the cellpadding, etc. So you could use CALL DEFINE inside PROC REPORT to alter the formatted width, as shown in the program below, but the "rest of the text" is just gone.

Notice how I can add FLYOVER text to LONGVAR2 in the code below. FLYOVER will only be surfaced in a popup window if 1) popups are enabled and 2) the user mouses over the cell with the FLYOVER attribute. In my example, the FLYOVER attribute is the same for every row, but if the variable being used for FLYOVER was different for every row, then every cell would have a different FLYOVER value.

cynthia
[pre]
ods html file='c:\temp\longvar_ex2.html' style=sasweb;

proc report data=longtxt nowd;
column name height longvar longvar2;
title '2) Using CALL DEFINE';
define name / display style(column)={just=c};
define height / display style(column)={just=c};
define longvar/display;
define longvar2 / display;
compute longvar;
if name = 'Lewis' then do;
call define(_col_,'format','$20.');
end;
else if name = 'Alice' then do;
call define(_col_,'format','$35.');
end;
endcomp;
compute longvar2;
flytxt='style={flyover="'||trim(longvar2)||'"}';
call define(_col_,'style',flytxt);
if name = 'Lewis' then do;
call define(_col_,'format','$20.');
end;
else if name = 'Alice' then do;
call define(_col_,'format','$35.');
end;
endcomp;
run;
ods _all_ close;
title; footnote;

[/pre]
Occasional Contributor
Posts: 10

Re: How to diguise text in ODS output

Hi Cynthia,

I think there is some misunderstanding. I come to that. But: I have a nice solution for what I want.

What I mean with "keeping the width" is as follows:
(in proc report)
define adres / order style=[width=110pt];

So I set the width of the column and I don't want this to be changed! The output-table (HTML) must always look the same.

The solution I am using is partly from the next link: http://www.blakems.com/archives/000077.html

In the Proc Report statement I use the following Style-blocks:
style(report)=[................. htmlstyle="table-layout:fixed"]
style(column)=[................. pretext='' posttext='']
To fix the column-width and to prevent long text to break to a new line.

And in a call define statement I use the following:
call define (_col_, 'style', 'style=[htmlstyle="text-overflow:ellipsis; overflow:hidden; white-space:nowrap" flyover="'||trim(adres)||'"]');

The result is:
- the cell-width keeps the same,
- in the cell you only see that part of the text that will fit in, but the "..." suggests there is more, (that is what I meant by "hiding ")
- a popup will show the complete text.
Ask a Question
Discussion stats
  • 4 replies
  • 432 views
  • 0 likes
  • 2 in conversation