Previous Page | Next Page

DATA Step Functions for Macros

RESOLVE Function



Resolves the value of a text expression during DATA step execution.
Type: DATA step function

Syntax
Details
Comparisons
Example
Resolving Sample References

Syntax

RESOLVE(argument)

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


Example


Example 1: Resolving Sample References

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.

Previous Page | Next Page | Top of Page