The RESOLVE function is a SAS function that evaluates and resolves a macro variable reference in a character string.
The Resolve function takes a character string as an argument and evaluates any macro variable references within that string. It then replaces the macro variable reference with its resolved value. The result of the RESOLVE function is a character string with all the macro variable references resolved.
Suppose we have a macro variable called “city” with the value “New York”. We can use the RESOLVE function to evaluate and resolve the macro variable reference in a character string. For example, the following code:
%let city = New York; data _null_; cityname=resolve('&city'); put cityname=; run;
will produce the following output:
As you can see, the variable cityname uses the RESOLVE function to resolve the macro variable reference in the character string.
Resolve function for macro invocation
This function is quite similar to the SYMGET function, but with the added ability to resolve macro names.
%macro procs; proc print data=sashelp.class obs=3; run; %mend procs; data _null_; var1=resolve('%procs'); put var1=; run;
var1=proc print data=sashelp.class obs=3; run;
DATA step variable with a macro invocation
%macro procs; proc print data=sashelp.class obs=3; run; %mend procs; data _null_; length var2 $ 1000; var2='%procs'; var2=resolve(var2); put var2=; run;
var2=proc print data=sashelp.class obs=3; run;
The macro variable created using CALL SYMPUT is not available for use until the data step has been executed.
One notable advantage of using the RESOLVE function is that it allows users to create a macro variable using the SYMPUT routine and immediately resolve its value within the same data step.
You can create a macro variable with the SYMPUT routine and use RESOLVE to resolve it in the same DATA step.
DATA temp; var='Hello'; CALL SYMPUT('res',var); resvar=RESOLVE('&res'); RUN;
If RESOLVE cannot locate the macro variable or macro identified by the argument, it returns the argument without resolution and the macro processor issues a warning message.
The RESOLVE function in SAS is a powerful tool that can help you resolve macro variables within a character string quickly and easily. This function is particularly useful when working with large amounts of code or text that contain macro variables. The RESOLVE function is efficient, flexible, and accurate, making it a valuable tool for SAS users.