<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Method to Temporarily set SAS option and then revert to original value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433648#M107536</link>
    <description>&lt;P&gt;Two procedures OPTSAVE and OPTLOAD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc OPTSAVE will save current settings to a data set and then Proc opload will read a data set to set options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example from the online help that displays a current option, saves options, changes it , shows the changed value, reloads the saved and the shows that the saved version has been restored. The example only shows one option but all options in effect are saved/ restored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname mysas "c:\mysas";

proc options option=yearcutoff;
run;
proc optsave out=mysas.options;
run;
options yearcutoff=2000;
proc options option=yearcutoff;
run;
proc optload data=mysas.options;
run;


proc options option=yearcutoff;
run;
&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Feb 2018 18:28:15 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-02-02T18:28:15Z</dc:date>
    <item>
      <title>Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433638#M107533</link>
      <description>&lt;P&gt;Does anyone know of a simple method of temporarily setting a SAS option and then reverting it back to it's previous value?&amp;nbsp; I maintain a large set of macro functions that are frequently used by my team.&amp;nbsp; Some of these functions need to have specific SAS options set (such as DLCREATEDIR or SASTRACE), but since these macros are generally just small parts of larger programs I don't want to unilaterally change a system option someone may be relying on later on in their program or which may cause unexpected behavior.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried some stuff where I use GETOPTION to save the original value of the option I need to change so I can change it back when my function has done it's piece, but this seems kind of hit and miss (for SASTRACE at least) and it seems like there should be a better, simpler way, although perhaps not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have some tips on handling situations like this?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 18:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433638#M107533</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2018-02-02T18:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433648#M107536</link>
      <description>&lt;P&gt;Two procedures OPTSAVE and OPTLOAD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc OPTSAVE will save current settings to a data set and then Proc opload will read a data set to set options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example from the online help that displays a current option, saves options, changes it , shows the changed value, reloads the saved and the shows that the saved version has been restored. The example only shows one option but all options in effect are saved/ restored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname mysas "c:\mysas";

proc options option=yearcutoff;
run;
proc optsave out=mysas.options;
run;
options yearcutoff=2000;
proc options option=yearcutoff;
run;
proc optload data=mysas.options;
run;


proc options option=yearcutoff;
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Feb 2018 18:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433648#M107536</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-02T18:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433665#M107540</link>
      <description>&lt;P&gt;That would be perfect, except the option I'm really having trouble with is SASTRACE, and that's one of the few options that cannot be saved or loaded with OPTSAVE/OPTLOAD unfortunately (according to PROC OPTIONS LISTOPTSAVE).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically it's any option where I need to set it with quotes like&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTION SASTRACE=',,t,dbs';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can pull the original value with:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET SASTrace_Opt = %SYSFUNC(GETOPTION(SASTRACE));&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But for some reason the normal quoting mechanisms aren't working when I try to use that variable later to set it back like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS SASTRACE=&amp;amp;SASTrace_Opt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've tried manually putting quotes around the value in many different ways, but it won't take it.&amp;nbsp; Does the macro processor get partially disabled or something on OPTIONS statements?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 18:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433665#M107540</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2018-02-02T18:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433724#M107558</link>
      <description>&lt;P&gt;I don't use Information Maps so don't think I can go much further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what does %put SAStrace_opt ; generate after running &lt;SPAN class="token macroname"&gt;%LET&lt;/SPAN&gt; SASTrace_Opt &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%SYSFUNC&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;GETOPTION&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;SASTRACE&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 23:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433724#M107558</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-02T23:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433738#M107562</link>
      <description>&lt;P&gt;I'm not sure what Information Maps are, the SASTRACE option affects SAS/ACCESS to relational DB products, or at least that's what I'm using it for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help thus far though.&amp;nbsp; I really wish that OPTLOAD/OPTSAVE would've worked here.&amp;nbsp; I hadn't heard of those previously so it's something to add to my toolkit in any case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code output you requested:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;119 17         %LET SASTrace_Opt = %SYSFUNC(GETOPTION(SASTRACE));
120 18         %PUT &amp;amp;=SASTrace_Opt;
121 SASTRACE_OPT=,,t,dbs
122 19         OPTIONS SASTRACE=&amp;amp;SASTrace_Opt;
123 NOTE: LINE GENERATED BY THE MACRO VARIABLE "SASTRACE_OPT".
124 19         ,,t,dbs
125             _
126             13
127 ERROR 13-12: UNRECOGNIZED SAS OPTION NAME ,.
128
129               _
130               13
131 19       ! ,,t,dbs
132              _
133              13
134 ERROR 13-12: UNRECOGNIZED SAS OPTION NAME T.
135
136 19       ! ,,t,dbs
137                ___
138                13
139 ERROR 13-12: UNRECOGNIZED SAS OPTION NAME DBS.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've also tried the following (and many other permutations, dealing with quoting gives me a headache, so I generally just go for a brute-force approach to get it to work right), all of which result in the same error:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET SASTrace_Opt = %STR(%')%SYSFUNC(GETOPTION(SASTRACE))%STR(%');
OPTIONS SASTRACE=&amp;amp;SASTrace_Opt

%LET SASTrace_Opt = %SYSFUNC(GETOPTION(SASTRACE));
OPTIONS SASTRACE=%STR(%')&amp;amp;SASTrace_Opt%STR(%');

%LET SASTrace_Opt = %SYSFUNC(GETOPTION(SASTRACE));
OPTIONS SASTRACE=%BQUOTE(&amp;amp;SASTrace_Opt);

%LET SASTrace_Opt = %STR(%')%SYSFUNC(GETOPTION(SASTRACE))%STR(%');
OPTIONS SASTRACE=%BQUOTE(&amp;amp;SASTrace_Opt);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2018 01:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433738#M107562</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2018-02-03T01:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433742#M107564</link>
      <description>&lt;P&gt;Probably easiest to just use double quotes, like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options sastrace="&amp;amp;SAStrace_Opt" ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think below is an example of saving, changing, and restoring the SASTRACE option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*set option ;
options sastrace=',,t,dbs' ;
%put &amp;gt;&amp;gt;%sysfunc(getoption(sastrace))&amp;lt;&amp;lt; ;

*store the option in a macro var ;
%let SASTrace_Opt = %SYSFUNC(GETOPTION(SASTRACE));

*change the option ;
options sastrace='' ;
%put &amp;gt;&amp;gt;%sysfunc(getoption(sastrace))&amp;lt;&amp;lt; ;

*restore the option ;
options sastrace="&amp;amp;SAStrace_Opt" ;
%put &amp;gt;&amp;gt;%sysfunc(getoption(sastrace))&amp;lt;&amp;lt; ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Feb 2018 01:46:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433742#M107564</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-02-03T01:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433745#M107566</link>
      <description>&lt;P&gt;Don't understand why you are having trouble.&amp;nbsp; You do need the quotes. You either add them back when you revert.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET optsave = %SYSFUNC(GETOPTION(SASTRACE));
options SASTRACE='something else';
options sastrace="&amp;amp;optsave";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could add the quotes when you create the macro variable. I would suggest storing the syntax needed to reset the option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET optsave = sastrace="%SYSFUNC(GETOPTION(SASTRACE))";
options SASTRACE='something else';
options &amp;amp;optsave ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2018 02:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/433745#M107566</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-03T02:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Method to Temporarily set SAS option and then revert to original value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/434611#M107865</link>
      <description>&lt;P&gt;That seems to be working, although I'd swear I'd tried that before and it wasn't, I guess my memory isn't what it used to be.&amp;nbsp; I still really wish that OPTSAVE/OPTLOAD worked for all of the options since that'd be a cleaner solution overall.&amp;nbsp; I wonder why it doesn't.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 17:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Method-to-Temporarily-set-SAS-option-and-then-revert-to-original/m-p/434611#M107865</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2018-02-06T17:32:18Z</dc:date>
    </item>
  </channel>
</rss>

