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-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
  • 3 replies
  • 788 views
  • 3 likes
  • 4 in conversation