BookmarkSubscribeRSS Feed
PhilC
Rhodochrosite | Level 12

Many people want to remove certain HTML elements generated by ODS HTML, but how do you add an HTML element?

 

Example: How does one add an horizontal rule (<HR> ) before and after some PROC ODSTEXT output?

9 REPLIES 9
ballardw
Super User
Look at the documentation for ODS Escapechar and the RAW function.
Cynthia_sas
SAS Super FREQ

Hi;

  Although RAW might work for HTML and RTF, I found that just using the tags in a TITLE and FOOTNOTE will also work. When you do insert HTML tags, you also need to remember to do a PROTECTSPECIALCHARS=OFF so that the HTML tag brackets are not "protected" by ODS:

Cynthia_sas_0-1588983849784.png

 

Hope this helps.

Cynthia

 

PhilC
Rhodochrosite | Level 12

@Cynthia_sas@ballardw 

There is something going on with my two SAS environments that is preventing this from working.  That is using "^{raw …}", using "^S={protectspecialchar=off>…" and "^{style[protectspecialchars=off] …}".

BTW, if the DIV tags are supposed to surround the HR then should it not be: ?

<div><hr/></div>
           ^

 

The loose parsing rules of HTML in web browsers probably interprets it correctly.

Cynthia_sas
SAS Super FREQ

Hi, yes, that should have been a /div at the end of the statement, my bad.

The ^S={xxx=yyy} is the original ESCAPECHAR syntax. the ^{style[xxx=yyy] .... } is the newest syntax for ESCAPECHAR. I have used the ^{raw} with HTML tags but not for just a HR. However, since you don't show all your code it's hard to comment. I started with the simplest approach first to do what you want, which was just to put horizontal rule on either side of the table. More advanced requirements might need the use of ^{raw} -- but protectspecialchars=off should always be specified, either in a style override or in a style template when you use HTML tags or RTF control strings.
Cynthia

PhilC
Rhodochrosite | Level 12

OK, got it to work with SAS Batch... But it doesn't work at all when I insert it into my code of ~650 lines, using SAS Batch.

My process in summary: I tried my code SAS batch, didn't work. Then tried this in Enterprise Guide, trying to keep it simple, using only your code, didn't work! Then I tried your code, keeping it simple, in SAS Batch, -- it works -- ( ^{Raw...} works as well  @ballardw ).

Now something is happening in my code that breaks this feature. And that may be out of the scope of this article.

 

Both of you helped solve this, thanks.  If I find out something useful I'll post it here.

PhilC
Rhodochrosite | Level 12

I could not get this to work:

ods escapechar= "^";
title1 "^{style[protectspecialchars=off] <div><hr/></div>}";
footnote "^{style[protectspecialchars=off] <div><hr/></div>}";
proc odstext;
  p "Note: the following totals should add together:" ;
  p "14B + 14C + 14E + 14F = 15B" / style=[color=purple fontsize=15pt];
run;
title;footnote;

but I could get this to work:

ods escapechar= "^";
proc odstext;
  p "^{style[protectspecialchars=off] <div><hr/></div>}";
  p "Note: the following totals should add together:" ;
  p "14B + 14C + 14E + 14F = 15B" / style=[color=purple fontsize=15pt];
  p "^{style[protectspecialchars=off] <div><hr/></div>}";
run;

I still don't know the reason behind why @Cynthia_sas's solution does not works in my code when using title and footnotes.  But I did succeed in putting the horizontal rules where I wanted them in the output.

 

Thanks again, for the help.

PhilC
Rhodochrosite | Level 12

This small sample worked in my SAS Batch SAS environment, but not in my Enterprise Guide environment:

ods noproctitle escapechar= "^" ;
ods html style=Festival ;
  title      "^{style[protectspecialchars=off] <div><hr/></div>}";
  footnote      "^{style[protectspecialchars=off] <div><hr/></div>}";

  proc odstext data=sashelp.class(obs=1) ;
    p 'Student Info' / style=systemtitle ;
    list ;
      item 'Student name is ' || name ;
      item 'Age: ' || put (age , 2. ) ;
      item 'Sex: ' || trim(sex) ;
      item 'Height: ' || put(height , 5.1 ) ;
    end;
  run;
  title ; footnote ;
  proc odstext data=sashelp.class(FIRSTOBS=2 obs=2) ;
    p 'Student Info' / style=systemtitle ;
    list ;
      item 'Student name is ' || name ;
      item 'Age: ' || put (age , 2. ) ;
      item 'Sex: ' || trim(sex) ;
      item 'Height: ' || put(height , 5.1 ) ;
    end;
  run;
ods html close ;

This is code works independent of the noproctitle option being set. 

PhilC
Rhodochrosite | Level 12

I just learned about this. This could be useful in situations using data steps.  

 

"LINE Method" from SAS® 9.4 ODS: Advanced Topics, 3e  

 

SAS Communities / Programming - ODS Object  

 

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
  • 9 replies
  • 914 views
  • 1 like
  • 3 in conversation