Jedi SAS Tricks: Reset SAS System Options

6

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:
GOPTIONS RESET;
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:
%OptionReset(!HELP)
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!
Mark

Share

About Author

SAS Jedi

Principal Technical Training Consultant

Mark Jordan (a.k.a. SAS Jedi) grew up in northeast Brazil as the son of Baptist missionaries. After 20 years as a US Navy submariner pursuing his passion for programming as a hobby, in 1994 he retired, turned his hobby into a dream job, and has been a SAS programmer ever since. Mark writes and teaches a broad spectrum of SAS programming classes, and his book, "Mastering the SAS® DS2 Procedure: Advanced Data Wrangling Techniques" is in its second edition. When he isn’t writing, teaching, or posting “Jedi SAS Tricks”, Mark enjoys playing with his grand and great-grandchildren, hanging out at the beach, and reading science fiction novels. His secret obsession is flying toys – kites, rockets, drones – and though he usually tries to convince Lori that they are for the grandkids, she isn't buying it. Mark lives in historic Williamsburg, VA with his wife, Lori, and Stella, their cat. To connect with Mark, check out his SAS Press Author page, follow him on Twitter @SASJedi or connect on Facebook or LinkedIn.

6 Comments

  1. Hi Jedi,can you explain me why we need to place option name in quotation marks,while syntax mentioned in help and documentation doesnt show any usage of quotation marks...???Even i wrote a code for testing this option which only works when quotation marks are included like this
    data _null_;
    opt=getoption("linesize","keyword");
    put opt=;
    run;
    If i exclude that quotation marks,
    Getting errors saying numeric values has converted to character values.

    • SAS Jedi

      Hey, Bhargav! In DATA step programming, all text literals must be delimited by quotes - either "text" or 'text'. Without the quotes, the complier will interpret the text as a variable name. So if you tried this:
      data _null_;
      opt=getoption(linesize,keyword);
      put opt=;
      run;

      you get an error. You CAN use variables to hold the text values for the getoptions function, so this code will work:
      data _null_;
      ls='linesize';
      kw='keyword';
      opt=getoption(ls,kw);
      put opt=;
      run;

      Regards,
      Mark

  2. I'm a co-founder of the brazilian website http://www.estatisti.co/ , focused on sharing news, articles and interviews related to Statistics and I'd like to have the honor to have you interviewed by us!

    We are 3 young entrepreneurs that are majoring in Statistics and we'd like to contribute to other students in this area with edifying information from professionals working with statistics, their experiences and opinions.

    If you accept, could you send us your email so we can give you the questions, please?

    Best Regards,
    João Victor

    • SAS Jedi

      Eu tenho experiençia minimo com estatística, mas seria um prazer ser entrevistado para o seu site. Meu e-mail: mark.jordan @ sas.com.
      Cordialmente,
      Mark

  3. That's cute. As a macro programmer, I use GETOPTION() a lot to store a user's setting of some option and then restore it at the end (to avoid an unwanted side-effect of having a macro change the user's environment), but hadn't thought about using that STARTUPVALUE argument for a global reset. Nifty.

Back to Top