SAS programming Skills
How to continue keeping temporary files after exiting SAS
How to re-direct work folder in SAS
How to re-direct all listing html/gragh output from SAS
Question 1: How do we still keep the temporary files in SAS work folder even after we exit SAS normally?
We can use the SAS system options to keep the temporary files in SAS work folder even after we exit SAS, here is the
noworkterm prevents the work data sets from being deleted
, it has no effect on initialization of the work library by SAS.
SAS normally initializes the work library at the start of each session, which effectively destroys any pre-existing information.
option prevents SAS from erasing existing work files on invocation.
option prevents SAS from erasing existing work files on termination.
If you see some error or warning message in he log window, like:
"WARNING: SAS option work is valid only at startup of the SAS System or startup of an environment within SAS. The SAS option is ignored.
this is because several SAS system options can only be set in the SAS configuration file or in the SAS command.
Question 2: How do I redirect work folder in SAS?
Answer: First we can use the following code to change the SAS work directory, but most of time you may find it's not working
since this evolves administrator authorization for SAS system options. options work="directory";
The other way to change the SAS work directory is running the following command in
start-up(be very careful, this may
brake your SAS installation
if there is
something wrong in the code, use system restore to recover
, just in case).
type the code in the target line
after you click windows --> startup)
sas.exe -CONFIG "C:\Program Files\SAS\9.2\nls\en\SASV9.CFG" -work "D:\temp"
Sometimes you may need the complete directory(right click SAS.exe --> properties, then you can find the direcotry for the configuration file):
"C:\Program Files\SAS\V8\sas.exe" -CONFIG "C:\Program Files\SAS\9.2\nls\en\SASV9.CFG" -work "D:\temp"
Then you can use the following code to test if you changed the work foloder successfully or not(output in the log window):
proc options option=work; run;
Question 3: How to re-direct all listing html/gragh output from SAS?
Sometimes when you generate SAS graph, html, pdf, or other listing, you may not realize you put all those files in some folder called:
Since this folder will not automatically delete after you exit from SAS; so one day you might say, "Oh, My....", there are several Gigebite of files in that folder
and make you run out of space on your server or computer.
The key is you may want to re-direct all those listing output to your temporary work folder, so those listing output will be automatically deleted after you exiting SAS.
There are several ways you can do this:
Another option is to run the following sas code, then it will automatically redirect all of the graphical output to temorary work folder:
ods listing gpath="%sysfunc(pathname(work))";
Or change the destination of html pdf output:
ods HTML body=html_name.html path=E:\folder\... ;
ods pdf (id=journalstyle) style=journal file='E:\folder\pdf_name.pdf' pdftoc=3;
/* pdftoc: number of level output in table of contents */
ods graphics on/height=12 in width= 10in;
Continue to next:
How to customize SAS appearance, html output, number lines?
SAS tutorial home
How to grab web content from page url by SAS?
Statistics tutorial home