BookmarkSubscribeRSS Feed
lgtea57
Calcite | Level 5
Hello,

I am trying to create interaction variables for a regression between 4 race dummy variables and several age category variables. My plan was to create a new variable name as a combo of the two variables used and then multiple the variables together creating the interaction variable. I've written the macro as follows:

%macro interaction(var);

data two; set one;
minority&var=minority*&var;
black_nonhisp&var = black_nonhisp*&var;
Asian_nonhisp&var = Asian_nonhisp &var;
other_nonhisp&var=other_nonhisp&var;

%mend interaction;

%interaction (_18to21);
%interaction (_22to24);
%interaction (_25to29);
%interaction (_30to34);
%interaction (_35to39);
%interaction (_40to44);
%interaction (_45to49);
%interaction (_50to54);
%interaction (_55to60);

run;

When I run the program I am getting errors (below) and was hoping for a little debugging help as this is one of my first times to write a macro.

Thanks!
21061 %interaction (_18to21);
NOTE: Line generated by the macro variable "VAR".
1 _18to21
-------
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL,
NOTIN, OR, ^=, |, ||, ~=.
3 REPLIES 3
lgtea57
Calcite | Level 5
Just to clarify, both variables are dummies.
ballardw
Super User
Looks like the lines:
Asian_nonhisp&var = Asian_nonhisp &var;
other_nonhisp&var=other_nonhisp&var;


maybe should be
Asian_nonhisp&var = Asian_nonhisp * &var;
other_nonhisp&var=other_nonhisp *&var;

in the macro definition.
lgtea57
Calcite | Level 5
Thanks! Your suggestions, along with moving the macro out of the original dataset and into a new one, did the trick. I appreciate you taking the time to read through my code!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 3721 views
  • 0 likes
  • 2 in conversation