<?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 How to stop a macro from trying to resolve in the definition rather than the actual code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774197#M246023</link>
    <description>&lt;P&gt;I'm trying to run something with the same logic as below. Basically, I want the macro 'Test' to insert the where statement and then resolve 'i' after it has done this as part of the do loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead it seems to be resolving 'i' whilst it is in the macro definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it is possible to do because I have just taken this macro out of a larger macro where it was running fine. (have moved out to improve efficiency)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help as to how to make 'i' not resolve until macro variable 'a' has been inserted into the code&amp;nbsp;is much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro Test(a);
%do i=4 %to 6;

data test&amp;amp;i.;
set sashelp.cars&amp;amp;a.;
run;

%end;
%mend Test;
%Test((where=(cylinders=&amp;amp;i.)));&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Oct 2021 12:41:04 GMT</pubDate>
    <dc:creator>EC27556</dc:creator>
    <dc:date>2021-10-14T12:41:04Z</dc:date>
    <item>
      <title>How to stop a macro from trying to resolve in the definition rather than the actual code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774197#M246023</link>
      <description>&lt;P&gt;I'm trying to run something with the same logic as below. Basically, I want the macro 'Test' to insert the where statement and then resolve 'i' after it has done this as part of the do loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead it seems to be resolving 'i' whilst it is in the macro definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it is possible to do because I have just taken this macro out of a larger macro where it was running fine. (have moved out to improve efficiency)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help as to how to make 'i' not resolve until macro variable 'a' has been inserted into the code&amp;nbsp;is much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro Test(a);
%do i=4 %to 6;

data test&amp;amp;i.;
set sashelp.cars&amp;amp;a.;
run;

%end;
%mend Test;
%Test((where=(cylinders=&amp;amp;i.)));&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Oct 2021 12:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774197#M246023</guid>
      <dc:creator>EC27556</dc:creator>
      <dc:date>2021-10-14T12:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a macro from trying to resolve in the definition rather than the actual code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774203#M246028</link>
      <description>&lt;P&gt;Why are you conducting a subsetting WHERE in a macro parameter? That doesn't really make sense to me, and it eliminates the warning when you include the subsetting on the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(a);
%do i = 4 %to 6;

data test&amp;amp;i.;
	set sashelp.cars (where = (cylinders = &amp;amp;i.));
run;

%end;
%mend test;
%test();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Oct 2021 12:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774203#M246028</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-10-14T12:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a macro from trying to resolve in the definition rather than the actual code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774204#M246029</link>
      <description>&lt;P&gt;What are you trying to accomplish here? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 12:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774204#M246029</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-10-14T12:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a macro from trying to resolve in the definition rather than the actual code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774210#M246032</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350407"&gt;@EC27556&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can mask the ampersand in the macro call using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n09tblrxldh8k0n1kt6dkj3xlxug.htm" target="_blank" rel="noopener"&gt;%NRSTR function&lt;/A&gt; and unmask it in the macro code using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1k3cotqhvgwk0n105gyfe1cqg9m.htm" target="_blank" rel="noopener"&gt;%UNQUOTE function&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;%macro Test(a);
%do i=4 %to 6;

data test&amp;amp;i.;
set sashelp.cars&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;%unquote(&lt;/FONT&gt;&lt;/STRONG&gt;&amp;amp;a.&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;;
run;

%end;
%mend Test;
%Test(&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;%nrstr(&lt;/STRONG&gt;&lt;/FONT&gt;(where=(cylinders=&amp;amp;i.))&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;)&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Oct 2021 13:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774210#M246032</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-10-14T13:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a macro from trying to resolve in the definition rather than the actual code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774211#M246033</link>
      <description>&lt;P&gt;The simplest way is to add single quotes around the value in the call and then use %SYSFUNC() to call DEQUOTE() to remove them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Test(dsnopts);
%do i=4 %to 6;

data test&amp;amp;i.;
set sashelp.cars( %sysfunc(dequote(&amp;amp;dsnopts%str( ))));
run;

%end;
%mend Test;
options mprint;
%Test(dsnopts='where=(cylinders=&amp;amp;i)');
%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Oct 2021 13:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774211#M246033</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-14T13:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a macro from trying to resolve in the definition rather than the actual code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774215#M246036</link>
      <description>&lt;P&gt;You are a genius, thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 13:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774215#M246036</guid>
      <dc:creator>EC27556</dc:creator>
      <dc:date>2021-10-14T13:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to stop a macro from trying to resolve in the definition rather than the actual code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774233#M246048</link>
      <description>&lt;P&gt;Basically I oversimplified things.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My real problem is more like the below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro Test(c,b,a);
%do i=4 %to 6;

data &amp;amp;c.&amp;amp;i.;
set sashelp.&amp;amp;b.&amp;amp;a.;
run;

%end;
%mend Test;
%Test(First,Cars,(where=(cylinders=&amp;amp;i.)));&lt;BR /&gt;%Test(Second,Cars,(where=(Cylinder_test=&amp;amp;i. and cylinder_true=&amp;amp;i.)));&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically i want 6 datasets - First4, First5, First6, Second4, Second5, Second6. But the second datasets come from a dataset that is laid out slightly differently and needs a different where statement - because different variable names etc..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could just write out 2 datasteps with different where statements however in my actual code i am creating hundreds of datasets so not really feasible - well it is it would just be a massive ugly program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The best was of doing this i thought was to create a where statement as a macro variable and insert back into the code. Then it just takes up 1 line of space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Probably not the best way of doing what i need to do but it's how my brain has framed the problem - in any case, someone has worked a solution below!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 14:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-stop-a-macro-from-trying-to-resolve-in-the-definition/m-p/774233#M246048</guid>
      <dc:creator>EC27556</dc:creator>
      <dc:date>2021-10-14T14:13:07Z</dc:date>
    </item>
  </channel>
</rss>

