DATA Step Functions for Macros |
Type: | DATA step function |
Syntax | |
Details | |
Comparisons | |
Example | |
Resolving Sample References |
Syntax |
RESOLVE(argument) |
can be one of the following items:
a text expression enclosed in single quotation marks (to prevent the macro processor from resolving the argument while the DATA step is being constructed). When a macro variable value contains a macro variable reference, RESOLVE attempts to resolve the reference. If argument references a nonexistent macro variable, RESOLVE returns the unresolved reference. These examples using text expressions show how to assign the text generated by macro LOCATE or assign the value of the macro variable NAME:
x=resolve('%locate'); x=resolve('&name');
the name of a DATA step variable whose value is a text expression. For example, this example assigns the value of the text expression in the current value of the DATA step variable ADDR1 to X:
addr1='&locate'; x=resolve(addr1);
a character expression that produces a text expression for resolution by the macro facility. For example, this example uses the current value of the DATA step variable STNUM in building the name of a macro:
x=resolve('%state'||left(stnum));
Details |
The RESOLVE function returns a character value that is the maximum length of a DATA step character variable unless you specifically assign the target variable a shorter length. A returned value that is longer is truncated.
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.
You can create a macro variable with the SYMPUT routine and use RESOLVE to resolve it in the same DATA step.
Comparisons |
RESOLVE resolves the value of a text expression during execution of a DATA step or SCL program, whereas a macro variable reference resolves when a DATA step is being constructed or an SCL program is being compiled. For this reason, the resolved value of a macro variable reference is constant during execution of a DATA step or SCL program. However, RESOLVE can return a different value for a text expression in each iteration of the program.
RESOLVE accepts a wider variety of arguments than the SYMGET function accepts. SYMGET resolves only a single macro variable but RESOLVE resolves any macro expression. Using RESOLVE might result in the execution of macros and resolution of more than one macro variable.
When a macro variable value contains an additional macro variable reference, RESOLVE attempts to resolve the reference, but SYMGET does not.
If argument references a nonexistent macro variable, RESOLVE returns the unresolved reference, whereas SYMGET returns a missing value.
Because of its greater flexibility, RESOLVE requires slightly more computer resources than SYMGET.
Example |
This example shows RESOLVE used with a macro variable reference, a macro invocation, and a DATA step variable whose value is a macro invocation.
%let event=Holiday; %macro date; New Year %mend date; data test; length var1-var3 $ 15; when='%date'; var1=resolve('&event'); /* macro variable reference */ var2=resolve('%date'); /* macro invocation */ var3=resolve(when); /* DATA step variable with macro invocation */ put var1= var2= var3=; run;
When this program executes, these lines are written to the SAS log:
VAR1=Holiday VAR2=New Year VAR3=New Year NOTE: The data set WORK.TEST has 1 observations and 4 variables.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.