DATA Step, Macro, Functions and more

how to write a macro name including multiple macro variables?

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

how to write a macro name including multiple macro variables?

data eq1;
input ID y x z w;
cards;
1 1 30 . 25
3 1 . 45 . 
4 1 48 25 56 
;
run;

%macro genmod(method,missper);
proc genmod data = &&method&missper;
		class y(ref='0') id;
  		model y= x z w/ dist=bin link=logit pred covb;
		repeated subject=id / type=ar(1) PRINTMLE;
     
      	ods output ParameterEstimates=&&method.lgs&missper;
    run;
%MEND genmod;
%genmod(eq,1);

Hello,

I am writing some MACRO. I know for above code example ( eq=method and missper=1 ), if I want to write 'eq1', I could use &&method&missper. But I want to know more complex writing way. For 'eqlgs1', I use &&method.lgs&missper. what about 'leq.gs1' or 'leq_1gs'? something like those. Any other way to write eqlgs1? 

 

Thanks


Accepted Solutions
Solution
‎04-05-2018 05:31 PM
SAS Employee
Posts: 2

Re: how to write a macro name including multiple macro variables?

[ Edited ]
Posted in reply to xiangpang

Here are a few examples from what you asked about:

 

%put will write the resolved text to the log.

 

When you use multiple &'s this is indirect referencing. Documentation: http://go.documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=mcrolref&docsetTarget=n0vl7...

 

See below:

 

%let method=eq;
%let missper=1;
%let method1=Hello;


/*eq1*/
%put  &method&missper;

/*eqlgs1*/
%put &method.lgs&missper;


/*leq.gs1*/
%put  l&method..gs&missper;

/*leq_1gs*/
%put l&method._&missper.gs;



/*When there are double ampersands in front of a macro variable, they are resolved to one ampersand. 
Then the next macro variable is resolved.
Finally the macro variable is rescanned and resolved. 
&&method&misper -> &method1 -> Hello
*/

%put &&method&missper;

  

View solution in original post


All Replies
Super User
Posts: 9,611

Re: how to write a macro name including multiple macro variables?

Posted in reply to xiangpang

Use the macro without the proc genmod, just put a %put into it, so you can experiment until you get it right.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,084

Re: how to write a macro name including multiple macro variables?

Posted in reply to xiangpang

You may want to test your macro coding with Options Mprint symbolgen; (turn off with Options Nomprint NosymbolgenSmiley Wink.

 

Check the rules for macro variable concatenation and the very significant difference between &var1.&var2 and &&var1&var2.

Solution
‎04-05-2018 05:31 PM
SAS Employee
Posts: 2

Re: how to write a macro name including multiple macro variables?

[ Edited ]
Posted in reply to xiangpang

Here are a few examples from what you asked about:

 

%put will write the resolved text to the log.

 

When you use multiple &'s this is indirect referencing. Documentation: http://go.documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=mcrolref&docsetTarget=n0vl7...

 

See below:

 

%let method=eq;
%let missper=1;
%let method1=Hello;


/*eq1*/
%put  &method&missper;

/*eqlgs1*/
%put &method.lgs&missper;


/*leq.gs1*/
%put  l&method..gs&missper;

/*leq_1gs*/
%put l&method._&missper.gs;



/*When there are double ampersands in front of a macro variable, they are resolved to one ampersand. 
Then the next macro variable is resolved.
Finally the macro variable is rescanned and resolved. 
&&method&misper -> &method1 -> Hello
*/

%put &&method&missper;

  

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 130 views
  • 3 likes
  • 4 in conversation