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
Related
What is this SAS note saying? ODS PDF(WEB) printed no output.
I have not requested the saving of a pdf file. This code is just at the beginning of my program code.
98 /* ODS STATEMENTS */
99 ODS LISTING GPATH='&sasworklocation';
100 ODS LISTING GPATH='c:\data';
101 ods path reset;
102 ods _ALL_ close;
NOTE: ODS PDF(WEB) printed no output.
(This sometimes results from failing to place a RUN statement before
the ODS PDF(WEB) CLOSE statement.)
ods trace off;
Thank you.
MM
If you're using SAS EG or Studio it submits some code at the beginning of each submission and teh end. You can turn the display of this code on/off but you cannot stop it. You likely have PDF selected as an output options somewhere or the automatic code is generating that message. You can probably ignore it safely.
To reduce log output in SAS University uncheck LOG Options-Show generated code in SAS log preferences.
SAS EG
Is there any way I can print the query/statement used to get the output, along with the output, using SAS ODS?
Suppose,
ods pdf file=pdfile;
proc sql;
select a.*
from tab1 a inner join tab2 b
on a.something=b.something
where <>
having <>;
quit;
ods _all_ close;
this would print the OUTPUT generated from the above query. But can I also get the query printed via the ods pdf along with the output?
There's no automatic way to redirect the log that I'm aware of.
There are a few ways to get what you want, however.
First off, if you are able to use Jupytr, SAS has plugins to enable that to work with SAS, and then you can simply write in the notebook and run the code, and the results appear with your code just as you want. See Chris Hemedinger's blog post on the subject for more details.
Second, SAS Studio will support a notebook-style interface probably with the next major revision (I believe version 5.0) which will release late next year. So similarly, you would put your code and get your output in the same windows.
Finally, the third option is to do as Reeza suggested - write to a log file, then print that to the output. It's messy but possible.
Here's an example of the latter. I don't make any effort to clean it up, note, you'd probably want to remove the logging related to PROC PRINTTO and the otehr notes (or turn on NONOTE).
ods pdf file="c:\temp\test.pdf";
filename logfile temp;
proc printto log=logfile;
run;
proc sql;
select * from sashelp.class;
quit;
proc printto;
run;
data _null_;
infile logfile;
input #1 #;
call execute(cats('ods text="',trim(_infile_),'";'));
run;
ods _all_ close;
I was doing a PCA analysis with SAS using the following code:
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
Because the lst files this analysis produces is too large, I used the NOPRINT option. However, it seems that the NOPRINT option also eliminates all of my ODS outputs. (Now PRINCEEV and PRINCEEVAL are all empty):
ERROR: File WORK.PRINCEEVAL.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
259 putn
_______
1
259 ! ame=YES; run;
WARNING 1-322: Assuming the symbol PUTNAMES was misspelled as putname.
ERROR: File WORK.PRINCEEV.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
ERROR: Errors printed on page 1.
Is there a way to suppress the generation of lst file, without affecting the ods output?
UPDATE:
It seems that according to the following sas blog, it is not possible to do that:
Can you combine NOPRINT and ODS OUTPUT?
SAS programmers crave efficiency. Upon reading that the NOPRINT option
can make a procedure run faster, the ambitious programmer might
attempt to run a procedure with the NOPRINT option but use the ODS
OUTPUT statement to capture the results of one table. Sorry, friend,
but you can't do that. The NOPRINT option means that no ODS tables are
created, so there is no way to select a table and save it to a data
set.
But the dilemma is, I have limited space on the cloud computing server. The lst files are doing nothing but wasting my spaces. Deleting the lst files when SAS programs are running with external processes will also produce an io error in SAS (I already tried that).
Is there anyway around?
I would suggest:
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
This will close the listing destination, so should work fine.
I noticed in a related blog post, Rick argued for:
ods exclude _all_ ;
http://blogs.sas.com/content/iml/2015/05/28/five-reasons-ods-exclude.html
Minor change to the previous answer: remove the NOPRINT option and after the ODS OUTPUT is created open up the ods listing if you have further code.
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) /*NOPRINT*/;
id time;
run;
ods output close;
ODS LISTING;
If you execute your sas-script on your cloud computing server via bash, then you can send your .lst files to /dev/null:
sas -print /dev/null script.sas
The -print option only effects your .lst, but not any ODS related outputs.
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;
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.