SAS® and R

Best of Both Worlds

SAS tip: Save and load system options

leave a comment »

It is good statistical programming practice to delete all temporary data sets at the end of a macro run, not just to save considerable work space and memory, but also reduce the chance for errors such as reusing the data set from previous run, or warning signs such as naming conflict.

But how about system options? In your macro call, you might need to change several system option settings, and it would be a hassle to reset them back to the original state one-by-one. Thankfully we have OPTSAVE and OPTLOAD procedures at our disposal, which can be used to save SAS option values, and restore them at a later time. In the following example the OPTSAVE procedure writes the values of all the SAS options that can be altered from within a SAS session to a SAS data set [your_saved_options]. The OPTLOAD procedure later restores the SAS session option values from the [your_saved_options] data set.

/* Save your SAS system options */
proc optsave out=[your_saved_options];

/* Reload your SAS system options */
proc optload data=[your_saved_dateset];

This way, SAS options can be reset back to the original values, before exiting the macro.


Written by sasandr

June 6, 2012 at 4:08 pm

Posted in SAS

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: