APPLY TEMPLATE Subcommand (AUTORECODE command)

The APPLY TEMPLATE subcommand allows you to apply a previously saved autorecode template to the variables in the current AUTORECODE command, appending any additional values found in the variables to the end of the scheme, preserving the relationship between the original and autorecode values stored in the saved scheme.

  • APPLY TEMPLATE is followed by an equals sign (=) and a quoted file specification.
  • All variables on the VARIABLES subcommand must be the same type (numeric or string), and that type must match the type defined in the template.
  • Templates do not contain any information on user-missing values. User-missing values for the target variables are based on the first variable in the original variable list with defined user-missing values. All other values from other original variables, except for system-missing, are treated as valid.
  • Value mappings from the template are applied first. All remaining values are recoded into values higher than the last value in the template, with user-missing values (based on the first variable in the list with defined user-missing values) recoded into values higher than the last valid value.
  • If multiple variables are specified on the VARIABLES subcommand, APPLY TEMPLATE generates a grouped recoding scheme, with or without an explicit GROUP subcommand.

Example

DATA LIST FREE /var1 (a1).
BEGIN DATA
a b d
END DATA.
AUTORECODE VARIABLES=var1
  /INTO newvar1
  /SAVE TEMPLATE='/temp/var1_template.sat'.
DATA LIST FREE /var2 (a1).
BEGIN DATA
a b c
END DATA.
AUTORECODE VARIABLES=var2
  /INTO newvar2
  /APPLY TEMPLATE='/temp/var1_template.sat'.
  • The template file var1_template.sat maps the string values a, b, and d to the numeric values 1, 2, and 3, respectively.
  • When the template is applied to the variable var2 with the string values a, b, and c, the autorecoded values for newvar2 are 1, 2, and 4, respectively. The string value "c" is autorecoded to 4 because the template maps 3 to the string value "d".
  • The data dictionary contains defined value labels for all four values--the three from the template and the one new value read from the file.
Table 1. Defined value labels for newvar2
Value Label
1 a
2 b
3 d
4 c