Desktop productivity for business analysts and programmers

Including custom CSS attributes and JavaScript

Reply
Regular Contributor
Posts: 150

Including custom CSS attributes and JavaScript

I need to be able to produce reports in EG that have pop-ups for text items that contain additional information. Actually the user I am building this for wants this for output data sets - I am pretty sure that is not possible - but I can do it with an HTML table. I have found a number of resources that allow me to do that using span tags, combined with CSS styles and some simple JavaScript. If I was doing this by coding my own ODS HTML statement I would simply use the headtext option. My question is how to best do this in EG? Based on some preliminary option it appears that the only option EG provides is to provide a custom style using the Manage Styles button in Options -> Results -> HTML.

Alternatively I might be able to package the code as a Stored Process where I have more control over HTML generation. This is only an option if the output data set created by the Stored Process can be linked to other code nodes in EG.

TIA for any advice/suggestions.
SAS Super FREQ
Posts: 8,818

Re: Including custom CSS attributes and JavaScript

Don:
If you search on the SAS site for "ODS HTML Javascript", you should find some Tech Support notes that talk about inserting JavaScript into ODS output (which would mean that you would not have to code all the HTML yourself):
http://support.sas.com/kb/23/645.html
http://support.sas.com/kb/23/381.html
http://support.sas.com/kb/?qm=3&la=en&ct=51012&qt=subject:%22javascript_1%22+

You can use a custom CSS file with ODS HTML -- either in or outside of EG -- EG just uses the STYLESHEET= option. The trick would be to make sure that your custom CSS file is in the right place on the server so it could be used when you want it to be used. You'd have this same issue (where does the style template live) if you used SAS style templates to insert the JavaScript (instead of CSS), as described here:
http://support.sas.com/kb/4/773.html

Also as far as popups go, you can use the FLYOVER style attribute with ODS HTML to turn on popup windows. When you hover your mouse over the F or M, you should see a popup window with extra text.

[pre]
proc format;
value $gend 'M' = 'Something for male students'
'F' = 'Different for female students';
run;

title; footnote;
options nodate nonumber;
ods listing close;

ods html file="c:\temp\show_flyover.html" style=sasweb;

proc print data=sashelp.class;
title 'Use FLYOVER in variable cells based on variable value';
var name age height;
var sex / style(data)={flyover=$gend.};
run;

ods html close;
[/pre]

To see an example of using CSS and lots of popup windows, look at this example:
[pre]

ods markup tagset=style_popup path='c:\temp' (url=none)
file='popup.html' style=sasweb
stylesheet='popup.css';

proc report data=sashelp.shoes nowd;
column region sales inventory returns;
define region / group;
rbreak after / summarize;
title 'Using style popup tagset template';
run;
ods markup close;
[/pre]

The style_popup tagset template uses JavaScript to change the color of the page element when you hover your mouse over it and when you double click after the cell turns salmon-orange, then a popup window appears with all the style information relevant to that table cell. That tagset template and custom CSS file were written by the developers as a diagnostic tool to help users figure out what style attributes were used in an ODS HTML table cells. But the coding/application of the different technologies (HTML, JavaScript, CSS) all happens within ODS. (when you use the simple STYLESHEET= option, SAS/ODS is MAKING a CSS file; when you use the STYLESHEET=(URL=...) option, SAS/ODS will use an EXISTING CSS file.)

That example may be overkill for what you want to do, but it shows the breadth of what is possible in Base SAS.

Also, if you go down the SP road, there are only certain client apps that can "receive" HTML from an SP. EG is one of them -- but WRS is not. So if you built your SP to gen some custom HTML, you'd be limiting where the SP could run. (...which might be OK for your purposes...)

cynthia
Regular Contributor
Posts: 150

Re: Including custom CSS attributes and JavaScript

Thanks Cynthia. Exactly the pointers I needed.

I had forgotten about the flyover attribute. It might meet the user's/client's needs. I thought I needed to do something more because the pop-up text could be long. Based on a quick check I ran using a modfied version of your example, the generated pop-up does wrap the text and can even extend beyond the results window and even the EG window.
Ask a Question
Discussion stats
  • 2 replies
  • 244 views
  • 0 likes
  • 2 in conversation