BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xiangpang
Quartz | Level 8
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

1 ACCEPTED SOLUTION

Accepted Solutions
brzcol
SAS Employee

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

3 REPLIES 3
ballardw
Super User

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

 

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

brzcol
SAS Employee

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;

  

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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