Skip to content

Macro Variable Manipulation

Chris Swenson edited this page Nov 14, 2020 · 3 revisions

Macro programs that create macro variables should do the following:

  • Delete similar macro variables that already exist to avoid conflicts.
  • Create the specified macro variables in the specified manner.
  • Report the macro variables created in a single list using SASHELP.VMACRO.
  • Allow for filtering of the input data (if possible).

The following macro programs create macro variables for use later in the code, except for DelVars, which deletes macro variables.

  • ColumnVars
    • Set macro variables for tables from SASHELP.VColumn, one variable per column.
    • Output: Multiple macro variables, one for each column.
  • DelVars
    • Delete all user macro variables. This is best used to clear out macro variables before moving on to another process in order to avoid conflicting or mistaken values. A list of macro variables can be excluded from deletion.
  • IntoList
    • Create a macro variable that is a list of values from a column in a data set. Optionally define the delimiter and filter the input data set.
    • Output: Single macro variable consisting of a list
  • ObsMac
    • Set observations in a data set to macro variables, using a specified prefix and the observation number to create the macro variable name. Optionally filter the input data set.
    • Output: 1-to-many macro variables with appended numbers
  • SetVars
    • Create one or more macro variables from the variable names in a data set. The generated macro variable can either be a list within one macro variable or multiple macro variables named with the specified prefix and appended observation number.
    • Output:
      • type=MULTI: 1-to-many macro variables with appended numbers
      • type=LIST: Single macro variable consisting of a list
  • TableVars
    • Generate macro variables for tables identified from SASHELP.VTABLE, naming the variables using the specified prefix and the observation number of the table. Useful when processing multiple data sets. Similar to ObsMac, but with a static source table.
    • Output: 1-to-many macro variables with appended numbers
  • VarMac
    • Create macro variables from two columns, where one column names the macro variable and another supplies the value. Optionally filter the input data set.
    • Output: 1-to-many macro variables

Notes

Please see the Macro Variable Manipulation Examples page for examples on how to use these programs.

Please set the Macro Variable Manipulation Demonstration page for a demonstration using these programs.

Main Pages

Subscriptions

CheckLog

Macro Variable Manipulation

Author

Clone this wiki locally