BookmarkSubscribeRSS Feed
Leon27607
Fluorite | Level 6

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?

2 REPLIES 2
CiCi
Fluorite | Level 6

* 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. 

Tom
Super User Tom
Super User

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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