<?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: Saving and restoring options using OPTSAVE and OPTLOAD in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968758#M376627</link>
    <description>&lt;P&gt;Sysindex may be problematic because of this: "&lt;EM&gt;&lt;SPAN&gt;You can use SYSINDEX in a program that uses macros when you need &lt;STRONG&gt;a unique number&lt;/STRONG&gt; that changes &lt;STRONG&gt;after each macro invocation&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN&gt;" (taken form documentation)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But maybe something like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro u_isnull(macvar);
   %if %symexist(&amp;amp;macvar.) %then %sysevalf(%superq(%superq(macvar)) =, boolean);
   %else 1
   %mend u_isnull;

%macro u_optstore(arg,caller);
   %put NOTE: &amp;amp;=SYSINDEX;
   %if %qupcase(&amp;amp;arg) eq SAVE or %u_isnull(arg) %then %do;
      proc optsave out=__optbase_&amp;amp;caller._;
         run;
      %end;
   %else %do;
      proc optsave out=__optcomp_&amp;amp;caller._;
         run;
      proc compare base=__optbase_&amp;amp;caller._ comp=__optcomp_&amp;amp;caller._ out=__optload_&amp;amp;caller._ outbase outnoequal noprint;
         run;
      proc optload data=__optload_&amp;amp;caller._;
         run;
      proc delete data=__optbase_&amp;amp;caller._ __optcomp_&amp;amp;caller._ __optload_&amp;amp;caller._;
         run;
      %end;
   %mend u_optstore;






options mprint;
%macro macro2();
  %put B;
  %local caller;
  %let caller=&amp;amp;sysmacroname.;
  %u_optstore(SAVE,&amp;amp;caller.)
  %put BB;
  %u_optstore(LOAD,&amp;amp;caller.)
  %put BBB;
%mend macro2;

%macro macro1();
  %put A;
  %local caller;
  %let caller=&amp;amp;sysmacroname.;
  %u_optstore(SAVE,&amp;amp;caller.)
  %put AA;
  %macro2()
  %put AAA;
  %u_optstore(LOAD,&amp;amp;caller.)
  %put AAAA;
%mend macro1;

%macro1()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The only restriction is that &amp;amp;CALLER. cannot be "to long".&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bart&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jun 2025 16:35:31 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2025-06-11T16:35:31Z</dc:date>
    <item>
      <title>Saving and restoring options using OPTSAVE and OPTLOAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968751#M376626</link>
      <description>&lt;P&gt;Below is the optsave/optload macro that I am currently using.&amp;nbsp; I'm not sure the code is mine or borrowed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It addresses the problem described in this discussion&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Why-does-Proc-OPTLOAD-change-the-PAGESIZE-to-55/m-p/799713#M314471" target="_blank"&gt;Solved: Why does Proc OPTLOAD change the PAGESIZE to 55? - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;by only reloading options that were changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to figure a way that this macro can be called from a macro that has already called it and not overwrite the data sets from the level above.&lt;/P&gt;
&lt;P&gt;unique data set names&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;macro1
   %u_optstore(SAVE)
 &amp;nbsp;&amp;nbsp;   change&amp;nbsp;options
&amp;nbsp;&amp;nbsp;&amp;nbsp;   macro2&amp;nbsp;&amp;nbsp;
         %u_optstore(SAVE)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;   change&amp;nbsp;options
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;   %u_optsave(LOAD)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;macro2 mend
    change more options maybe.
    %u_optstore(LOAD);
    macro1 mend
      &lt;/PRE&gt;
&lt;P&gt;Maybe create a unique global macro variable to save a unique call index.&amp;nbsp; &amp;amp;SYSINDEX involved I think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro u_isnull(macvar);
   %if %symexist(&amp;amp;macvar.) %then %sysevalf(%superq(%superq(macvar)) =, boolean);
   %else 1
   %mend u_isnull;

%macro u_optstore(arg);
   %put NOTE: &amp;amp;=SYSINDEX;
   %if %qupcase(&amp;amp;arg) eq SAVE or %u_isnull(arg) %then %do;
      proc optsave out=__optbase__;
         run;
      %end;
   %else %do;
      proc optsave out=__optcomp__;
         run;
      proc compare base=__optbase__ comp=__optcomp__ out=__optload__ outbase outnoequal noprint;
         run;
      proc optload data=__optload__;
         run;
      proc delete data=__optbase__ __optcomp__ __optload__;
         run;
      %end;
   %mend u_optstore;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 15:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968751#M376626</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-06-11T15:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Saving and restoring options using OPTSAVE and OPTLOAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968758#M376627</link>
      <description>&lt;P&gt;Sysindex may be problematic because of this: "&lt;EM&gt;&lt;SPAN&gt;You can use SYSINDEX in a program that uses macros when you need &lt;STRONG&gt;a unique number&lt;/STRONG&gt; that changes &lt;STRONG&gt;after each macro invocation&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN&gt;" (taken form documentation)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But maybe something like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro u_isnull(macvar);
   %if %symexist(&amp;amp;macvar.) %then %sysevalf(%superq(%superq(macvar)) =, boolean);
   %else 1
   %mend u_isnull;

%macro u_optstore(arg,caller);
   %put NOTE: &amp;amp;=SYSINDEX;
   %if %qupcase(&amp;amp;arg) eq SAVE or %u_isnull(arg) %then %do;
      proc optsave out=__optbase_&amp;amp;caller._;
         run;
      %end;
   %else %do;
      proc optsave out=__optcomp_&amp;amp;caller._;
         run;
      proc compare base=__optbase_&amp;amp;caller._ comp=__optcomp_&amp;amp;caller._ out=__optload_&amp;amp;caller._ outbase outnoequal noprint;
         run;
      proc optload data=__optload_&amp;amp;caller._;
         run;
      proc delete data=__optbase_&amp;amp;caller._ __optcomp_&amp;amp;caller._ __optload_&amp;amp;caller._;
         run;
      %end;
   %mend u_optstore;






options mprint;
%macro macro2();
  %put B;
  %local caller;
  %let caller=&amp;amp;sysmacroname.;
  %u_optstore(SAVE,&amp;amp;caller.)
  %put BB;
  %u_optstore(LOAD,&amp;amp;caller.)
  %put BBB;
%mend macro2;

%macro macro1();
  %put A;
  %local caller;
  %let caller=&amp;amp;sysmacroname.;
  %u_optstore(SAVE,&amp;amp;caller.)
  %put AA;
  %macro2()
  %put AAA;
  %u_optstore(LOAD,&amp;amp;caller.)
  %put AAAA;
%mend macro1;

%macro1()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The only restriction is that &amp;amp;CALLER. cannot be "to long".&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bart&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 16:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968758#M376627</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-06-11T16:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Saving and restoring options using OPTSAVE and OPTLOAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968767#M376628</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, this is good idea.&amp;nbsp; &amp;nbsp;You could use&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n19g1rkeq1al87n1djihhoec4oxp.htm" target="_blank"&gt;SAS Help Center: %SYSMEXECNAME Macro Function&lt;/A&gt;&amp;nbsp;to retrieve the name of the calling macro.&amp;nbsp; &amp;nbsp;But I think all we need to know is the depth of the call&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n19g3xotkajctbn1tujf4pce6n3d.htm" target="_blank"&gt;SAS Help Center: %SYSMEXECDEPTH Macro Function&lt;/A&gt;&amp;nbsp;and not have to worry about the length of the caller's name.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro u_isnull(macvar);
   %if %symexist(&amp;amp;macvar.) %then %sysevalf(%superq(%superq(macvar)) =, boolean);
   %else 1
   %mend u_isnull;

%macro u_optstore(arg);
   %put NOTE: %nrstr(%%)sysmexecdepth=%sysmexecdepth;
   %put NOTE: &amp;amp;=depth;
   %local /readonly depth=%sysmexecdepth;
   %if %qupcase(&amp;amp;arg) eq SAVE or %u_isnull(arg) %then %do;
      proc optsave out=__optbase_&amp;amp;depth.__;
         run;
      %end;
   %else %do;
      proc optsave out=__optcomp_&amp;amp;depth.__;
         run;
      proc compare base=__optbase_&amp;amp;depth.__ comp=__optcomp_&amp;amp;depth.__ out=__optload_&amp;amp;depth.__ outbase outnoequal noprint;
         run;
      proc print;
         run;
      proc optload data=__optload_&amp;amp;depth.__;
         run;
      proc delete data=__optbase_&amp;amp;depth.__ __optcomp_&amp;amp;depth.__ __optload_&amp;amp;depth.__;
         run;
      %end;
   %mend u_optstore;

%put %nrstr(%%)sysmexecdepth=%sysmexecdepth;

%u_optstore(save)

%macro macro2();
  %put %nrstr(%%)sysmexecdepth=%sysmexecdepth;
  %put B;
  %u_optstore(SAVE)
  %put BB;
  %u_optstore(LOAD)
  %put BBB;
%mend macro2;

%macro macro1();
  %put %nrstr(%%)sysmexecdepth=%sysmexecdepth;
  %put A;
  %u_optstore(SAVE)
  %put AA;
  %macro2()
  %put AAA;
  %u_optstore(LOAD)
  %put AAAA;
%mend macro1;

%macro1()

%u_optstore(LOAD);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968767#M376628</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-06-11T17:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Saving and restoring options using OPTSAVE and OPTLOAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968768#M376629</link>
      <description>&lt;P&gt;Yes, that's better idea!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With just a small modification:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   %put NOTE: %nrstr(%%)sysmexecdepth=%sysmexecdepth;
   %local / readonly depth=%sysmexecdepth;
   %put NOTE: &amp;amp;=depth;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to avoid:&lt;/P&gt;
&lt;P&gt;"WARNING: Apparent symbolic reference DEPTH not resolved."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968768#M376629</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-06-11T17:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Saving and restoring options using OPTSAVE and OPTLOAD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968770#M376630</link>
      <description>I hadn't tested that change.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Saving-and-restoring-options-using-OPTSAVE-and-OPTLOAD/m-p/968770#M376630</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-06-11T18:02:06Z</dc:date>
    </item>
  </channel>
</rss>

