BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DMoovendhan
Quartz | Level 8
Hi, This is my requirment, we are working on set of macros which are interrelated to each other, and the initial program that executes sets the system options as required. Once done this will be deployed to the user end. The user will be able to execute his own codes after initiating the session. To give the expected output in particular format, we need to make sure that the sas options are not changed during execution. Is there any way that we can lock the options been set after the execution of the initial program. Kindly advice. Thanks, Mooovendhan Devaraj
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Look into using PROC OPTSAVE in the initial macro and then let the the other macro(s) use OPTSAVE/PROC COMPARE to determine if there have been changes and reset them using OPTLOAD.

 

I use this technique in macro where I want to preserve and reset the users options after I change them in my macro.

 

   /*------------------------------------------------------------------------*
    | Reset system options changed by the macro.
    *------------------------------------------------------------------------*/
   proc optsave out=&m._optsave2;
      run;
   proc compare noprint base=&m._optsave1 compare=&m._optsave2 outbase outnoequal out=&m._optchange;
      run;
   data _null_;
      set &m._optchange;
      if _N_ eq 1 then put 'NOTE: The following options are being reset to previous values.';
      put 'NOTE- ' (OPTNAME OPTVALUE)(=);
      run;
   proc optload data=&m._optchange(keep=optname optvalue);
      run;

 

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Probably not.  Another approach would be to capture the original option settings, and then restore options to those original values as your macro begins to execute.

ballardw
Super User

If a Macro or program requires specific options I would recommend making sure that they are available when needed. You can use the OPTSAVE procedure to capture a users options and OPTLOAD to set the options you need and then restore the users options after the options are no longer needed.

 

Since the OPTLOAD uses a dataset then your implementation of the preferred options would be calling the procedure with a dataset containing the options needed.

 

So your macros could contain code like:

 

Proc optsave out=lib.useropts;run;

Proc optload data=permlib.macroopts;run;

<other macro code>

Proc optload data=lib.useropts;run;

 

 

 

data_null__
Jade | Level 19

Look into using PROC OPTSAVE in the initial macro and then let the the other macro(s) use OPTSAVE/PROC COMPARE to determine if there have been changes and reset them using OPTLOAD.

 

I use this technique in macro where I want to preserve and reset the users options after I change them in my macro.

 

   /*------------------------------------------------------------------------*
    | Reset system options changed by the macro.
    *------------------------------------------------------------------------*/
   proc optsave out=&m._optsave2;
      run;
   proc compare noprint base=&m._optsave1 compare=&m._optsave2 outbase outnoequal out=&m._optchange;
      run;
   data _null_;
      set &m._optchange;
      if _N_ eq 1 then put 'NOTE: The following options are being reset to previous values.';
      put 'NOTE- ' (OPTNAME OPTVALUE)(=);
      run;
   proc optload data=&m._optchange(keep=optname optvalue);
      run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 702 views
  • 2 likes
  • 4 in conversation