Sas Results Viewer - Start at top of new output - sas

This is another usability oriented question for me...
Is there a way to have the results viewer "auto-position" itself at the top of the most recent output when something new is submitted?
Sometimes the results viewer shows the bottom of the just-generated table. Sometimes, it shows the top of a table, but not of the "topmost" table (i.e. in the middle of new results).
This behavior is akin to surfing the web and having chrome open a new webpage at the bottom... it really doesn't make sense and takes time away from viewing the results while trying to find the actual top of the new results, which can sometimes be very long and mixed up with other previous results.
A partial workaround, is to have the logs/results viewer clear during each run, which at least makes it easy to page to the top of the current results, but I still have to actually page up, which just seems silly. Here is what I use to clear logs and the output viewer from the code. Is there a better set of commands to use?
*Clear prior run's result viewer list and log window*;
ods html close; /* close previous */
DM log "OUT;CLEAR;LOG;CLEAR;" log continue ;
DM log 'next results; clear; cancel;' whostedit continue ;
ods html; /* open new */

You can! By understanding that:
ODS HTML destination generates HTML source that has the default anchor <ANAME=IDX#n> before each proc's output. The anchor name prefix can be altered with the ODS HTML ANCHOR= option.
Proc TEMPLATE can be used to create a custom style that utilizes a style attribute such as POSTHTML to inject a HTML snippet into the destination that is JavaScript code.
The injected JavaScript can assign location.hash to the expected initial anchor name. This will force the browser to navigate to that anchor.
Example:
proc template;
define style topnav; /* name of style to specify when opening ODS HTML */
parent=styles.htmlblue; /* name of style to use for thematic desire */
/* JavaScript to be injected into destination */
style body from body /
posthtml="<script>location.hash='#IDX';</script>";
end;
run;
ods html
path="C:\temp"
body="sample.html"
style=topnav /* specify the custom style */
;
proc print data=sashelp.cars;
run;
proc print data=sashelp.class;
run;
ods html close;

Related

SAS ODS not to open output

In the following code, I would like to print an excel sheet and do not open it once the code ends, does anyone know how to do this because the ods excel close does not work. There is an option in the SAS 9.4 platform to not open the output but when I choose than and open a new SAS session the option is reverted. Anyone knows something about it? Thanks :)
ods listing close;
ods excel file="path.xlsx"
/*ods excel file="path.xlsx"*/
/* will apply an appearance style */
/*style=calibri*/
options(
/* for multiple procs/sheet */
sheet_interval="none"
/* name the sheet tab */
sheet_name="filename"
);
/* add some formatted text */
ods escapechar='~';
ods text="~S={font_size=14pt font_weight=bold}~filename";
proc print data=data noobs;
run;
ods excel close all;
ods listing;
Tazz:
Problem
You should look at the SAS log for ERROR messages. In future questions be sure to add ERROR messages. Do you get this message ? (### is the source code line number)
### ods excel close all;
---
22
202
ERROR 22-322: Syntax error, expecting one of the following: ;, ANCHOR, AUTHOR, BOX_SIZING,
CATEGORY, CLOSE, COMMENTS, CSSSTYLE, DOM, DPI, FILE, GFOOTNOTE, GTITLE, IMAGE_DPI,
KEYWORDS, NOGFOOTNOTE, NOGTITLE, OPTIONS, SASDATE, STATUS, STYLE, TEXT, TITLE,
WORK.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
So, this statement of yours is invalid
ods excel close all;
Fix
Use instead either
ods excel close;
or
ods _all_ close;
Be forewarned, the first time you run the code Excel will open the output. If you leave the results open in Excel and run the code again you will get a different ERROR:
ERROR: File is in use, ....
because the destination will still be open and SAS will not be able to write to it.
Turn off results viewing
ODS RESULTS OFF;
The ODS destination will be written to. The automatic viewing of results and results tracking as new items in the Results tab will not happen.
The setting is not programmed in, it's in the GUI.
Tools>Options>Preferences>Results
Uncheck: View results as they are generated

Display webout HTML generated by data steps in a SAS Web Report Studio

Here is how I build reports for SAS EnterpriseGRC:
I write sas base or macro code to collect and process data using
procs and data steps.
Then I use file _webout; in data steps and use
put statements to generate html
Then I register this code as a stored process and define filters which I am already handling in the code.
And then I navigate to Reports tab in EGRC and wala I have a report
For example my code would look like:
proc sql noprint;
CREATE TABLE work.risks AS
SELECT *
FROM opdetail.risk_L;
quit;
data _null_;
file _webout;
put '<html>';
put '<body>';
put '<table>';
put '<tr><td>Risk ID</td><td>Risk RK</td></tr>'
run;
data _null_;
set work.risks;
put '<tr>';
put '<td>'; put risk_id;'</td>'
put '<td>'; put risk_rk;'</td>'
put '</tr>';
run;
data _null_;
put '</table>';
put '</body>';
put '</html>';
run;
Now this is a very simplistic approach but a very effective one since I can theoretically represent my data in any complicated form like a correlation heat etc, as much as HTML allows
Now this technique has only one problem. Clients have a problem printing this report from within EGRC. The code I have written produces a stream output so I cant use this STP in a SAS Web Report Studio report where printing options are available. How can I solve my printing problem in the least complicated way?
p.s I know can build Informationmaps and build reports like they are supposed to but sometimes clients request demands a format of report which SAS Web Report Studio can not handle.
I could put this Print This Page in the HTML, but that puts date and page title on the top of printing page which is out of my control.
Well the least complicated way was to put a javascript print function through HTML inside the report. Though if someone IS still looking for a proper solution than ODS is the answer
Well the simplest way to print your _stream'd html report is via your trusty web browser!
Simply navigate to www.YOURSASMIDTER/SASStoredProcess and select "List Available Stored Processes and Reports". When you find your STP, right click and open in a new tab.
You now have your html report, and the URL which can be shared with end customers - who can apply your registered filters, and print your report in their browser of choice.
Of course this is not a the recommended way to build web based reports with SAS. Your SAS code will get overcomplicated by many / complex put statements (mixing SAS code with html/css/javascript). You will also struggle to apply the thousands of excellent libraries that can jazz up your report (such as highcharts, handsontable, d3).
If you are happy to deliver your reports purely from the browser (instead of EGRC) then a suggested / more scaleable approach is to use the open source SASjs adapter. More info at https://sasjs.io

SAS column width for HTML output

I am trying to make adjustments to my HTML output from SAS ODS.
This is all I have:
ODS HTML FILE = 'C:\filename.html' options(pagebreak='no');
proc print data=dataset noobs;
run;
ODS HTML CLOSE;
RUN:
Ideally, I would just have columns have an autofit if possible.
Any help is appreciated.
Take the default style, and modify it so that the DATA style element (see documentation here) has the white-space:nowrap CSS style applied to it. Save the changes to a new style called 'my_style'.
The white-space:nowrap is the bit of magic that will force the text not to line-break once it gets too long.
proc template;
define style my_style;
parent = styles.default;
style data from data / htmlstyle="white-space:nowrap";
end;
run;
Print out the table using out new modified style:
ods html style=my_style;
proc print data=sashelp.webmsg;
run;
ods html close;
Some more notes.... Sometimes SAS will actually support the actual CSS style that you need to change in which case you should use that (instead of htmlstyle=). Find the complete list here.
Also, your default style may not actually be named styles.default. To find the name of your default style, go to Tools->Preferences->Results and get the name from the 'Style' dropdown box. This is for the base SAS editor. For EG, it may be slightly different but I'm sure you'll be able to find it.

Turn off automatic graph saving in SAS 9.4

In SAS 9.3, I could use ODS HTML GPATH to specify the path where I wanted graphs to be saved (if I so desired). In 9.4, by default (i.e. every time I open SAS) whenever I make a graph (with PROC SGPLOT, e.g.), it automatically saves the plot to the location where the SAS program is saved. I've tried going to Tools --> Options --> Preferences --> Results and unchecking every combination of the HTML and ODS options, but no matter what I'm still getting automatically saved graphs. How can I turn this off? Preferably I'd still have ODS output within SAS, but I do not want these PNG (or whatever) images to be saved to my computer outside SAS automatically.
EDIT: More information because the differences as stated above were not clear.
1) In 9.3 I had to say ODS GRAPHICS ON and specify ODS HTML GPATH in order to have SAS save my plots to my computer outside of SAS (or so I thought). If I wanted ODS graphics inside of SAS, but not save graphs outside of SAS, I could just say ODS GRAPHICS ON and skip the ODS HTML GPATH statement.
2) When I open 9.4 and do not make any statements about ODS (i.e. leave settings at default), but run a procedure such as SGPLOT, I A) get both a html graph (ODS graph that shows up in SAS's 'Results' window) and a graph that I can double-click to open in Windows Photo Viewer, and B) the plot is additionally and automatically saved where my SAS program is located as a PNG.
Trying to stop this automatic graphing saving, I have tried the following in SAS 9.4 before running PROC SGPLOT:
1) ODS GRAPHICS OFF: Nothing changes. I still get everything listed in point (2) above.
2) ODS HTML CLOSE (with ODS GRAPHICS ON): Lose html/ODS version of graph within SAS, but still have graph in SAS I could double-click that opens in Windows Photo Viewer, and still the graph saves automatically to my SAS program's location.
3) ODS GRAPHICS OFF and ODS HTML CLOSE: Same thing as previous case ((2) directly above).
What I want (and I feel like this is how it was in 9.3) is to yes, have ODS graphs come up within SAS (don't really need the version you can double-click to open in Windows Photo Viewer), but no, do not have SAS save a PNG to my computer (specifically, my SAS program's location).
First off, a few notes about what you tried.
ODS GRAPHICS on/off will not have any real effect on SGPLOT or any of the SG procedures; they are all ODS GRAPHICS no matter what. What it does affect is PROC UNIVARIATE and similar procedures that have two types of graphics - old style graphics and ODS GRAPHICS. ODS GRAPHICS ON tells them to use ODS GRAPHICS, and OFF tells them to use the older method.
ODS HTML CLOSE will tell SAS not to produce HTML output, but as long as you have another destination open (ODS LISTING?) it will produce graphs still to the GRAPH destination. Addtionally, the fact that it still produces graphics at all with ODS HTML CLOSE (as opposed to the note "No output destinations active" and no output) tells me you still have a destination open (again, probably LISTING). Thus, ODS HTML GPATH will not necessarily solve your problem (as it will only impact where the HTML output will go). You need to set GPATH for each open destination (which is either LISTING, HTML, or both, depending on the checkboxes in your preferences).
The solution:
Since you want it to go away, your best bet is to make it in your work directory (which is cleaned up by SAS when it properly shuts down).
ods listing gpath="%sysfunc(getoption(work))";
proc sgplot data=sashelp.class;
vbar sex;
run;
Note that the .png files are created (as they always are), but now they go into the work catalog (which you can browse like a sub-library and see each of the files inside).
You could put the initial line in an autoexec.sas file and tell SAS to run that when SAS starts up (-AUTOEXEC option on command line).
You also could uncheck Listing in tools->preferences->Results, and/or use ODS LISTING CLOSE;, and those files should not appear.
Go to Tools --> Options --> Preferences --> Results and uncheck Create listing. It should take care of the automatic saving of PNG files to your program files.
In 9.3, when ODS HTML is on, graphs are defaulted to the user's home directory. They are saved to the hard drive, even if you don't specify a path. Otherwise, there is no way for the browser to display the images. The default location may have moved in 9.4 (I don't have a copy to test), but both versions put png files on your hard drive.

Determine ODS settings

I am working inside a SAS macro application, and get the following warning before running a proc compare:
WARNING: No output destinations active.
Using the noprint option of proc compare does not suppress the warning. Am pretty sure the only way to get rid of this warning is to open an ODS destination (eg ods listing;) before running the proc, however I do not want to disrupt existing settings as there may be different ODS states at run time.
Is there any way to determine the ODS state programmatically? eg:
%let state=%sysfunc(getODSSTATE(listing)); /* for example */
ods listing;
proc compare base=x compare=y noprint; run;
ods listing &state; /* either %str(CLOSE) or %str() */
I had thought ODS SHOW; would be a solution, but that tracks the select/exclude, not the open destination.
One solution might be to choose a destination that is unlikely to be open - an obscure tagset perhaps - and open that to a dummy file, then close it. ODS PREFERENCES;also seems like a good compromise; it will open up whatever your default destination is, at least.
Honestly though, if you're writing a macro application, I would just leave the ODS alone; it should be up to the programmer using your macro to properly set up ODS ahead of time.