interact Create interaction variables interact

Visualizing Categorical Data: interact

$Version: 1.0 (18 Mar 2001)
Michael Friendly
York University

The interact macro ( [download] get interact.sas)

Create interaction variables

The INTERACT macro creates interaction variables, formed as the product of each of the variables given in one set (V1=) with each of the variables given in a second set (V2=).

Usage

The INTERACT macro is called with keyword parameters. The arguments may be listed within parentheses in any order, separated by commas. For example:
  %interact(v1=age sex, v2=I1 I2 I3);

Parameters

DATA=
The name of the input dataset. If not specified, the most recently created dataset is used.
V1=
Specifies the name(s) of the first set of variable(s).
V2=
Specifies the name(s) of the second set of variable(s).
OUT=
The name of the output dataset. If not specified, the new variables are appended to the input dataset.
PREFIX=
Prefix(s) used to create the names of interaction variables. The default is 'I_'. The names are of the form I_11 I_12 ... I_1m I_21 I_22 ... I_nm, where there are n variables in V1 and m variables in V2.
CENTER=
If non-blank, the V1 and V2 variables are mean-centered prior to forming their interaction products.

Example

Here we generate dummy variables for GROUP (GA and GB) and SEX (SF), and their interactions, SG11 and SG12.
%include vcd(interact);        *-- or include in an autocall library;
%include vcd(dummy);

data test;
   input y group $ sex $ @@;
cards;
10  A M 12  A F 13  A M  18  B M 19  B M 16  C F 21  C M 19  C F 20  C M
;

%dummy (data=test, var=sex group, prefix=s g) ;
%interact(data=test, v1=sf, v2=ga gb, prefix=sg);
proc print; run;
This gives
OBS     Y    GROUP    SEX    SF    GA    GB    SG11    SG12

 1     10      A       M      0     1     0      0       0
 2     12      A       F      1     1     0      1       0
 3     13      A       M      0     1     0      0       0
 4     18      B       M      0     0     1      0       0
 5     19      B       M      0     0     1      0       0
 6     16      C       F      1     0     0      0       0
 7     21      C       M      0     0     0      0       0
 8     19      C       F      1     0     0      0       0
 9     20      C       M      0     0     0      0       0

See also

dummy Macro to create dummy variables