One of my students emailed me, asking how to easily reset SAS system options. He was looking for a one-liner solution, just like you get with graphic options:
While there isn't a RESET keyword for the OPTIONS statement, you can save your options settings before making changes using PROC OPTSAVE, and then easily restore the original values using PROC OPTLOAD. However, as the student pointed out, that's all well and good if you remembered to save your options before you made changes, but what do you do if the changes have already been made and you really don't want to re-start your SAS? So I rooted around in the SAS functions list, and discovered GETOPTION(), a little-known gem that should enable me to write my own OptionReset macro. I experimented with a little demo code to see how it worked:
options ls=80 PS=18; data _null_; length option $1024; option=getoption("linesize",'keyword','startupvalue'); putlog "NOTE: at startup: " option; option=getoption("linesize",'keyword'); putlog "NOTE: currently: " option; run; SAS LOG: NOTE: at startup: LINESIZE=100 NOTE: currently: LINESIZE=80
That was interesting! Now, to modify the DATA step to build and execute the OPTIONS statement that would re-set the option to its original value. I tried this:
options ls=80 PS=18; data _null_; length statement $1500; statement =cat('OPTIONS ',getoption("linesize",'keyword','startupvalue'),';'); putlog "NOTE: Resetting system option: " statement ; call execute(statement ); run; SAS LOG: NOTE: Resetting system option: OPTIONS LINESIZE=100;
After re-running the original data step, I could see that my option had been reset!
NOTE: at startup: LINESIZE=100 NOTE: currently: LINESIZE=100
Next, I added a SET SASHELP.VMACRO statement to leverage the dictionary table view, working through all of the appropriate options. We'll exclude the options reserved for SAS invocation...
options ls=80 PS=18; data _null_; length statement startup current $1024; set sashelp.voption; /* Exclude options you can't change while SAS is executing */ where optstart ne 'startup' and optname not in ('AWSDEF','FONT'); startup=getoption(optname,'startupvalue'); current=getoption(optname); if startup ne current then do; PUTLOG "NOTE: OptionReset Macro Resetting " optname " from " current " to " startup "."; statement =cat('OPTIONS ',getoption(optname,'keyword,startupvalue'),';'); call execute(statement ); end; run; SAS LOG: NOTE: OptionReset Macro Resetting LINESIZE from 80 to 100 . NOTE: OptionReset Macro Resetting PAGESIZE from 18 to 21 . ... NOTE: CALL EXECUTE generated line. 1 + OPTIONS LINESIZE=100; 2 + OPTIONS PAGESIZE=21;
With a little extra work, I wrapped this in a parameterized macro, allowing me to choose an indivdual option to rest, or to reset them all. The macro is in the ZIP file for this blog. After compiling the macro (OptionReset.sas) submit:
to see syntax help in the SAS log.
I keep a copy of this macro in my AUTOCALL path and can call it whenever I want to reset a SAS system option to the start-up value.
Until next time, may the SAS be with you!