Using the Additional Generated Code

When the SAS code for the User-Written Staging transformation is generated, additional code is generated and precedes the user-written code. This additional code provides information that can be useful in the user-written code. The generation of this additional code is controlled by the options on the User-Written page of the Staging Parameters tab.

Macro Variables

Macro variables for any extended attributes can be entered on the Extended Attributes tab of the User-Written Staging Properties dialog box. The name of each extension is the macro variable name, and the value of the extension is the value of the macro variable. If the name has spaces or other invalid characters, they are removed.
&input
If there is a source table to the transformation, then this macro variable contains the libref.tablename of the source table.
&target1–&targetn
These macro variables contain the names of the n target tables in the libref.tablename format.

Macros

These macros are available for use with user-written staging transformations.
  • The following macro generates table options for specified target tables.
    %macro _ITMS_tableOptions (targetTableNum=, 
                              targetTableName=,        
                              generateTableName=YES,
                              generateIndexes=YES);
    
    • The value for targetTableNum= can be an integer from 1 to n, where n represents the total number of target tables. These values are the same values that are represented by the macro variables &target1, … &target[n] in the generated code.
      The value for targetTableName= is a two-level SAS data set name in the form [libref].[table]. An example of this parameter is targetTableName=STG7536.NTSYSTEM_ITRM.
      Note: You can specify a table by using either the targetTableNum= parameter or the targetTableName= parameter. If both parameters are left blank, then the table options for all the target tables are generated.
    • If you specify generateTableName=NO, the macro generates a list of the table options.
    • If you specify generateTableName=YES, the macro generates the table name with the table options in parentheses after it.
  • The following macro generates an ATTRIB statement for each column of the requested table.
    The value for targetTableNum= is an integer from 1 to n, where n represents the total number of target tables. These values are the same values that are represented by the macro variables &target1, … &target[n] in the generated code.
    The value for targetTableName= is a two-level SAS data set name in the form [libref].[table]. An example of this parameter is targetTableName=STG7536.NTSYSTEM_ITRM.
    Note: You can specify a table by using either the targetTableNum= parameter or the targetTableName= parameter. If both parameters are left blank, then the macro generates an ATTRIB statement for each column for all tables.
    The ATTRIB statement includes the column name, type, length, format, informat, and label.
    %macro _ITMS_attrib (targetTableNum=, targetTableName=);
  • The following macro generates assignment statements for all the columns of the requested table that set the value to " " or . (missing), depending on the type of column.
    The value for targetTableNum= is an integer from 1 to n, where n represents the total number of target tables. These are the same values represented by the macro variables &target1, … &target[n] in the generated code.
    The value for targetTableName= is a two-level SAS data set name in the form [libref].[table]. An example of this parameter is targetTableName=STG7536.NTSYSTEM_ITRM.
    Note: You can specify a table by using either the targetTableNum= parameter or the targetTableName= parameter. If both parameters are left blank, then the macro generates assignment statements for all columns in all tables.
    %macro _ITMS_assignToMissing (targetTableNum=, targetTableName=);
  • The following macro generates a statement for each computed column of the requested table.
    The value for targetTableNum= is an integer from 1 to n, where n represents the total number of target tables. These are the same values represented by the macro variables &target1, … &target[n] in the generated code.
    The value for targetTableName= is a two-level SAS data set name in the form [libref].[table]. An example of this parameter is targetTableName=STG75.NTSYSTEM_ITRM.
    Note: You can specify a table by using either the targetTableNum= parameter or the targetTableName= parameter. If both parameters are left blank, then the macro generates a statement for each computed column for all tables.
    %macro _ITMS_computedColumns (targetTableNum=, targetTableName=);
  • The following macro generates a list of all the columns of the requested table.
    The value for targetTableNum= is an integer from 1 to n, where n represents the total number of target tables. These are the same values represented by the macro variables &target1, … &target[n] in the generated code.
    The value for targetTableName= is a two-level SAS data set name in the form [libref].[table]. An example of this parameter is targetTableName=STG75.NTSYSTEM_ITRM.
    Note: You can specify a table by using either the targetTableNum= parameter or the targetTableName= parameter. If both parameters are left blank, then the macro generates a list of all the columns for all tables.
    %macro _ITMS_columnList (targetTableNum=,
                             targetTableName=,
                             delimiter=,  
                             sqlAlias=); 
    The additional parameters allow the list to be generated in different ways:
    DELIMITER=
    This parameter is set to a character string that is placed between each column in the list. The most common value of this parameter is a comma, so that the list can be used in SQL code. If a value is not specified, then the column names are separated by blanks.
    SQLALIAS=
    This parameter is an alias that can be used as a prefix for each column name. There is a period between this prefix and the column name. The most common use of this parameter is in SQL when a table alias is needed for each column.

Tabinfo and Varinfo

You can choose to create the Tabinfo and Varinfo tables in the Work library. These tables can be used in the user-written code to generate SAS code that is based on the target table and column information.
The Tabinfo table contains one record for each target table. The following columns are included in the Tabinfo table:
TABLENM
specifies the name of the table.
LIBREF
specifies the libref for this table.
ISCOMPRESSED
specifies the COMPRESS data set option. The values can be YES (that is, COMPRESS=YES) or NO (that is COMPRESS=NO).
INDEXOPTION
specifies the INDEX data set option (if there is an index on the table).
The Varinfo table contains one record for each column in all the target tables. The following columns are included in the Varinfo table:
TABLENM
specifies the name of the table.
VARNM
specifies the name of the column.
VARLAB40
specifies the column label.
VARFMT
specifies the column format.
VARINFMT
specifies the column informat.
VARLEN
specifies the length of the column.
VARTYPE
specifies the type of the column. The type can be C (that is, character) or N (that is, numeric).
FORMULA
specifies the expression that is used to create this column, if it is a computed column.