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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2993 views
  • 0 likes
  • 2 in conversation