So I am trying to write a Macro to do backwards selection based on change in estimate(I know SAS has an automatic backwards selection process but it bases it off P-value). I had written a Macro for another project earlier but used proc surveylogistic then, this time I am using proc mixed. I have edited the code and thought that it should work but I am having issues with the interaction effect in proc mixed. When I assign a value to a macro variable inside a macro it doesn't like the * symbol. I get a syntax error, the weird thing is this would work fine outside of a macro. %Let Interaction = A*B; works fine but inside a %Macro if I say %Macro(explanatory = A B A*B) it complains with the error.
Another similar error is when I drop the first variable from the model it drops part of the interaction as well. AKA if I tell it to drop A, it drops the A from A*B so it becomes *B.
Outside the macro my code is simply...
proc mixed data=Input;
class B cat1 cat2 cat3 cat4;
model response = A B A*B cat1 cat2 cat3 cat4 explan1 explan2 explan3 /solution;
ods output solutionF = Sol1;
run;
Inside the macro it is
proc mixed data=&data;
class B &catvar;
model &response = &covars /solution;
ods output solutionF = Sol&i;
run;
when I get to a part
call symput("rcovars", reducedlist);
where Reducedlist is the list of the model after I drop a variable I get
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, -, /, :, _ALL_,
_CHARACTER_, _CHAR_, _NUMERIC_.
ERROR 200-322: The symbol is not recognized and will be ignored.
the * is underlined.
Main issue: Why can't we simply make a macro variable with a * sign inside a macro and is there a solution to this? Is there some way to create a variable that counts as A*B aka C or something but not so it is referenced as A*B but rather just C?
* is a special character and you need to mask it when assigning to a macro variable. Try the macro function %STR to mask *. Not sure how your "%Let Interaction = A*B;" works, but try to use "%let Interaction=%str(A B A*B);". The same solution for your macro problem.
See more details from thel link below
https://v8doc.sas.com/sashtml/macro/z3514str.htm
Hope it can help.
Turn on MPRINT option to see what actual code you macro is generating. There is nothing wrong with what you have posted.
%let data=Input;
%let catvar=cat1 cat2 cat3 cat4 ;
%let response=response;
%let covars=A B A*B cat1 cat2 cat3 cat4 explan1 explan2 explan3 ;
%let i=1 ;
%macro xx ;
proc mixed data=&data;
class B &catvar;
model &response = &covars /solution;
ods output solutionF = Sol&i;
run;
%mend xx;
options mprint;
%xx;
Which generates
MPRINT(XX): proc mixed data=Input; MPRINT(XX): class B cat1 cat2 cat3 cat4; MPRINT(XX): model response = A B A*B cat1 cat2 cat3 cat4 explan1 explan2 explan3 /solution; MPRINT(XX): ods output solutionF = Sol1; MPRINT(XX): run;
If you macro variables look like they have the right values then perhaps you need to remove any macro quoting so that it is not confusing the SAS parser.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.