Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

Resolve to Gain Total Control of Macro References

The RESOLVE function, like SYMGET, is a data step function used to resolve macro variable references. In addition, the RESOLVE function can resolve macros and data step variables containing macro references, making it far more powerful. It can also control whether that resolution occurs at compilation time or execution time.

The type of quotation marks used determines when a macro variable is resolved. If double quotes are used then resolution takes place at compilation time and the value returned can only be the value held at the outset. If single quotes are used then resolution is delayed until execution time (i.e. when the data step is processing the data) and the current value for the macro variable is returned.

In the example below, %let is used to set a macro variable value at compilation time and call SYMPUT is used to change that value during execution time. Alternative methods of achieving the same are also shown.

%let timing = Initial;

data demo_one;  
 call symput('timing','Updated');

 resolve1 = resolve("&timing");
 other1 = "&timing";  
 put "Compilation time: " resolve1= other1=;
   resolve2 = resolve('&timing'); 
other2 = symget('timing');
put "Execution time: " resolve2= other2=;

Compilation time: resolve1=Initial other1=Initial
Execution time: resolve2=Updated other2=Updated

The contents of a macro (not just a macro variable) can also be resolved. That macro can contain further macro calls or macro variables and the timing of their resolution can also be controlled. Forcing a macro to resolve at execution time cannot be achieved in any other way.

Uniquely to the RESOLVE function, macro references within the text of data step variables can also be resolved. In this instance, because the values of data step variables are used, resolution can only occur at execution time.

%let colour = Red;

%macro test;
  Inside macro colour is &colour 

data demo_two; 
   call symput ('colour','Blue');

   resolve3 = resolve("%test"); *Compile time; 
   other3 = "%test";

   resolve4 = resolve('%test'); *Execution time;

   data1 = 'Data variable colour is &colour'; 
   resolve5 = resolve(data1); run;

resolve function

As with SYMGET, the resolve function can construct a macro variable name from data step values. Again, because the values of data step variables are used, resolution can only occur at execution time.

It should also be noted that RESOLVE and SYMGET differ in the way they treat unresolved macro variables. SYMGET will return a missing value whereas RESOLVE will return the unresolved macro reference.