Clear the results viewer in SAS 9.4? - sas

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'.

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

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.

Get ODS output table names without actually having to run a PROC?

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.

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.

PROC APPEND massive log size is crashing Enterprise Guide

I am using Enterprise Guide 4.2 (no choice about this).
I am using PROC APPEND to append about 80k+ observations to a SQL Server table. I believe that there are some issues with the format of the data (such as mismatching variable lengths), but it executes just fine and the table is updated. Then, Enterprise Guide gives me the following message:
The contents of Log(af771r01 (Process Flow)) is too large to display. The window will close, but the contents will remain in the project.
I was able to successfully disable the log by redirecting it to a dummy file:
** The Append Proc below outputs 80k+ lines (in theory) to the log, crashing EG 4.2;
** This statement will temporarily disable logging;
FILENAME JUNK DUMMY;
PROC PRINTTO
LOG=JUNK;
RUN;
** ========================================================
** Archive Summarized Enrollment Data
** ========================================================;
PROC APPEND BASE = Archive.MnthlyMbrCmpArch (
SASDATEFMT=(SYS_SRC_LOAD_DT='mmddyy10.')
)
DATA = Work.R1_MBR_ENRL_ARCHIVE;
RUN;
** Reenable logging;
PROC PRINTTO;
RUN;
This prevents EG from crashing, but I'm losing all of the warning and error messages. I am trying to debug the statement so I want the warnings and errors, I just don't want a flooded log.
Is there a way to partially disable logging without turning it off completely? Or is there a way to redirect the log to a file so that EG doesn't crash while trying to not open it?
I am new to SAS and am open to any suggestions, even if they do not directly answer the question.
Yes, you can redirect the log to a file by specifying a path in the FILENAME statement (instead of saying DUMMY, which refers to a non-existing file):
FILENAME JUNK 'path/file-name.log';
Of course, you must have "write" permission to the location you specify.
You can suppress a lot of information from the log by using:
options nonotes nonotes2;
And/or:
options nomprint nomlogic nosymbolgen nomacrogen; /* IF CODE CONTAINS MACROS */
Errors will still be printed to the screen but you would have little information to debug them unless you turned the logging back on.
Some SAS Documentation: http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001906177.htm