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.
Related
Here is another issue I'm facing with SAS:
I have to write a full paper/report in SAS and can't find how to do so. So I already have a multitude of coding (to clean the data, create some new variable, merge three datasets, etc etc etc. I also made some tables and a few plots in the whole process). Now what I need to do for the project is: Write a scientific paper of a only a few pages (introduction, methodology, results, discussion, ...) in SAS. (I think the teacher said something about ods text ="blablabla..." to insert the text.) And of course use some of the tables/plots from my previous coding in this. This paper should be exported into a pdf file.
I was thinking of using
ODS TRACE ON;
...
ODS TRACE OFF;
for the tables I made (code for the creation of the tables is between those two lines of code). But then I just don't understand how I can re-use this output later on when creating my pdf-paper with:
ODS PDF FILE ='c:\...'
...
ODS PDF CLOSE;
I was hoping I could just 'trace' all of the tables and plots I needed in my code. And than open this pdf file, add some titles, some text, some of the tables/plots in between the text, and close the pdf file. However, I have a bad feeling it isn't as simple as that. :'(
Thanks in advance!
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
I have this Macro A. Everytime I run it, I get a result as the image below (include 2 tables and 1 graph). Note that this time I copied them from SAS output window and paste it on Excel then format it manually. My question is, when I run Macro A multiple times, how can I export all the results to a single specific Excel Sheet, one after another automatically?
Since I'm kinda a beginner in SAS, so a simple solution is preffered :)
Thanks a bunch!!
SAS result in excel
Use ODS Excel and sheet_interval option. This assumes SAS 9.4+
Ods excel file='myfile.xlsx' options(sheet_interval='none') style=meadow;
%macro_run();
Ods excel close;
Within the macro you may need to add:
Ods excel options(sheet_interval='none');
When I searched, all the results came up for SAS 9.3. That suggested I use the commands:
ods html close; *STOPS WRITING TO THE CURRENT RESULTS VIEWER;
ods html; *OPENS A NEW RESULTS VIEWER;
I'm running SAS 9.4 (Base SAS) and this doesn't work for me, which leads me to the conclusion that the way to clear the results viewer has changed from SAS 9.3 to SAS 9.4.
What to do?
I believe you need to run the following:
dm 'odsresults; clear';
or just type odsresults;clear in the SAS command box. This works for me in 9.3, can't see why it would be different in 9.4.
For further info - http://support.sas.com/kb/4/159.html
If you're in Enterprise Guide, the default results viewer corresponds to the ODS destination 'SASREPORT', so closing and re-opening the HTML destination won't do what you're expecting. Look at the very top of your log in EG, and find the ODS statement that is automatically included there. You can do an ODS _ALL_ CLOSE; later in your program, and then copy-paste that ODS statement from the top of your log... that should then effectively throw away whatever output was generated up the that point, and you'll only see whatever came after you re-opened the SASREPORT destination.
If this works, you will probably then want to examine the copy-pasted ODS statement and remove any unnecessary options etc.
EDIT: after reading your follow-ups, and still assuming that you're in EG ('Base SAS' is just a language and doesn't have a results viewer of its own) then go to Tools -> Options -> Results General and update your Replace Results setting to either 'prompt without replacing' or 'prompt before replacing'.
Question: is there a way to just get the ODS table names from a PROC without running the program up to that point with ods trace on?
Background: I often need to output an ODS data set from a PROC, but the only method I know of to get the list of available data sets is to insert
ods trace on;
before the PROC, then run the program, then review the log file to find the appropriate data set name, then insert my ods output statement, and re-run.
In a time-consuming program, that process can take a lot of time, and it just seems inefficient to have to run a program in order to figure out how to continue programming.
I can't find any SAS documentation that lists the available ODS tables by PROC, but if something like that exists, that would be a great answer to this question. I know the ODS output tables vary depending on which options are specified, but it still seems like a comprehensive list could be compiled, with notes about whether each table is dependent on PROC-specific options.
I'd also love it if there were something like a meta-PROC where a PROC name could be specified, and the ODS table names are returned, without running any other code.
There is a compilation in the SAS doc. This is for 9.4, but there is one in all the versions.
http://support.sas.com/documentation/cdl/en/odsug/66611/HTML/default/viewer.htm#p0mnbijm0t6w1cn1dpf3q5suxk4u.htm
You can run it with options obs=1; (just reset to obs=max later) if the output procedure is capable of running with zero observations (in general, if you're not doing any programmatic code generation, this is probably the case). You can also likely create a test procedure run that does not use your actual data (although that depends on what you're doing). (You cannot use obs=0, as that would produce no output.)
For example:
options obs=1;
ods trace on;
proc freq data=sashelp.class;
run;
ods trace off;
options obs=max;
You also may be able to determine the names from the installed templates, if it is a procedure that uses templates. For example, PROC FREQ does.
Bring up the Results explorer, and right click on the "Results" node up at the top. Select "Templates". That opens the Template explorer. Then look about for your procedure. Most of the statistical procedures are in Sashelp.Tmplstat. FREQ is not, however; it is in Sashelp.Tmplbase, under Base.Freq. Each of the PROC FREQ entries that starts with define table ... is a separate ODS table; the primary ones for PROC FREQ are Onewayfreqs and CrosstabFreqs, but generally all of the ones with a similar icon to those are tables (the blue ones are dynamic variables).
For PROC REG, for example, it is in the SASHELP.tmplstat folder (SASHELP.tmplstat.Reg), and has a few dozen tables available to see, generally with logical names. Not every table is produced from every run (it depends on what you ask for and what the PROC decides is needed), and I'm not sure every single one is available to intercept via ODS, but most of them are.