You are here: Administration Riser Bar>Using Macro Variables>Using Macro Variables in an Expression

DataFlux Data Management Studio 2.7: User Guide

Using Macro Variables in an Expression

Overview

You can use the getvar() and setvar() functions to dynamically retrieve and set macro variables in an expression.

In the sample job shown above, Data Source 1 specifies a source table. The Expression 1 node specifies the following expression:

string value_of_macro_var

value_of_macro_var = getvar("MIGRATION_MACROVAR1", "MIGRATION_MACROVAR1 not defined!")

The first line adds a new column, value_of_macro_var, to the output table for the Expression 1 node. The second line uses the getvar() function to retrieve a value that is specified in a macro variable that is called MIGRATION_MICROVAR1. If MIGRATION_MICROVAR1 does not have a value, the expression returns an error message.

In order to focus on how macro variables are created and how they can be referenced in an expression, assume that the job flow above has been created, and that only the following tasks remain:

It is assumed that you are familiar with the getvar() and setvar() functions. For more information about these functions, see "Using getvar() and setvar()" in the DataFlux Expression Language Reference Guide.

Create the Macro Variable Definition

The easiest way to add a macro variable definition is to use the Macro Files folder in the Administration riser. Macro variable definitions added here are stored in the macros.cfg file in your user profile directory by default. Perform the following steps:

  1. On the Administration riser, open the Macro Files folder and right-click the macros item. Then, click New Macro in the information pane at right to display the New Macro dialog.
  2. Enter a name (such as MIGRATION_MACROVAR1) and a value (such as 3) for the macro variable. This is equivalent to the following macro variable definition: MIGRATION_MACROVAR1=3
  3. Click OK to save the macro variable definition. The new macro variable is added to the list in the information pane, as shown in the following display:

Add the Expression to the Job

For the current example, assume that the following job flow has been created and is open in the data job editor.

Perform the following steps to add an expression with a getvar() function.

  1. Right-click the Expression 1 node and select Properties.
  2. Click the Pre-processing Expression tab.
  3. Add the expression with the getvar() function to the tab, as shown in the following display:

  4. Click OK to close the dialog.

Run the Job and Review the Output

You can confirm that the macro variable worked by running the job. Perform the following steps:

  1. Run the job.
  2. Select the Expression node. Then, click the Preview tab. Note the last column (value_of_macro_var) shown in the following display:

Documentation Feedback: yourturn@sas.com
Note: Always include the Doc ID when providing documentation feedback.

Doc ID: dfU_T_Macros_Expression.html