<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Putting complex text in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680089#M205457</link>
    <description>&lt;P&gt;Hi all. I am doing many iterative full joins on different sets of variables. I would like to create a macro to simplify things, but I am not sure how to put the necessary code containing the variables into the macro. Here is a partially macroed version that works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1x; input idx var1x $ var2x $; datalines;
1 moob shmoob
2 groob hoob
3 gloob poob
4 bloob poob
;
run;

data data1y; input idy var1y $ var2y $; datalines;
1 moob shmoob
2 froob bloob
3 gloob poob
4 gloob bloob
;
run;

%macro match (a,b);
proc sql;
create table match&amp;amp;a. as
select *
	from data&amp;amp;b.x as x full join data&amp;amp;b.y as y
	on x.var1x=y.var1y and x.var2x=y.var2y;
quit;
%mend match;

%match(2,1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this is what I would like to do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro match (a,b,matchvars);
proc sql;
create table match&amp;amp;a. as
select *
    from data&amp;amp;b.x as x full join data&amp;amp;b.y as y
	on &amp;amp;matchvars.;
quit;
%mend match;

%match(2,1,x.var1x=y.var1y and x.var2x=y.var2y);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I get this error: "ERROR: Invalid macro parameter name x.var1x. It should be a valid SAS identifier no longer than&amp;nbsp;32 characters."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I successfully put this complex string of text into the macro? Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 28 Aug 2020 19:53:46 GMT</pubDate>
    <dc:creator>kpberger</dc:creator>
    <dc:date>2020-08-28T19:53:46Z</dc:date>
    <item>
      <title>Putting complex text in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680089#M205457</link>
      <description>&lt;P&gt;Hi all. I am doing many iterative full joins on different sets of variables. I would like to create a macro to simplify things, but I am not sure how to put the necessary code containing the variables into the macro. Here is a partially macroed version that works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1x; input idx var1x $ var2x $; datalines;
1 moob shmoob
2 groob hoob
3 gloob poob
4 bloob poob
;
run;

data data1y; input idy var1y $ var2y $; datalines;
1 moob shmoob
2 froob bloob
3 gloob poob
4 gloob bloob
;
run;

%macro match (a,b);
proc sql;
create table match&amp;amp;a. as
select *
	from data&amp;amp;b.x as x full join data&amp;amp;b.y as y
	on x.var1x=y.var1y and x.var2x=y.var2y;
quit;
%mend match;

%match(2,1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this is what I would like to do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro match (a,b,matchvars);
proc sql;
create table match&amp;amp;a. as
select *
    from data&amp;amp;b.x as x full join data&amp;amp;b.y as y
	on &amp;amp;matchvars.;
quit;
%mend match;

%match(2,1,x.var1x=y.var1y and x.var2x=y.var2y);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I get this error: "ERROR: Invalid macro parameter name x.var1x. It should be a valid SAS identifier no longer than&amp;nbsp;32 characters."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I successfully put this complex string of text into the macro? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 19:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680089#M205457</guid>
      <dc:creator>kpberger</dc:creator>
      <dc:date>2020-08-28T19:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Putting complex text in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680090#M205458</link>
      <description>&lt;P&gt;just use %str to quote the string in macro. Check my codes with some typo correction.&lt;/P&gt;&lt;PRE&gt;%macro match (a,b,matchvars);
proc sql;
create table match&amp;amp;a. as
select *
	from data&amp;amp;b.x as x full join data&amp;amp;b.y as y
	on &amp;amp;matchvars.;
quit;
%mend match;

%match(2,1,%str(x.var1x=y.var1y and x.var2x=y.var2y));&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Aug 2020 19:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680090#M205458</guid>
      <dc:creator>MINX</dc:creator>
      <dc:date>2020-08-28T19:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Putting complex text in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680092#M205460</link>
      <description>Perfect, thank you! That works. I edited the post to remove the typos.</description>
      <pubDate>Fri, 28 Aug 2020 19:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680092#M205460</guid>
      <dc:creator>kpberger</dc:creator>
      <dc:date>2020-08-28T19:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Putting complex text in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680094#M205461</link>
      <description>&lt;P&gt;Instead of attempting to pass a value like "x.var1x=y.var1y" use the mnemonic EQ instead of =&lt;/P&gt;
&lt;P&gt;such as "x.var1x eq y.var1y"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the forms of passing parameters is called keyword and uses&amp;nbsp; varname= value in the parameters.&lt;/P&gt;
&lt;P&gt;So when the macro processor sees&amp;nbsp; %somemacro (x.var1x=y.var1y ) as the parameter string it thinks you are attempting to assign the value "y.var1y" to a macro variable named "x.var1x" , which is not a legal name for a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you could also do something like&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;%match(2,1,%str (x.var1x=y.var1y and x.var2x=y.var2y) );&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;The %str (&amp;nbsp; parameter text )&amp;nbsp; will mask the meaning of some of the characters like =. though not so much if you use % or &amp;amp;.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 20:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Putting-complex-text-in-a-macro/m-p/680094#M205461</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-28T20:00:30Z</dc:date>
    </item>
  </channel>
</rss>

