<?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 Re: Use macro value to conditionally print variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-value-to-conditionally-print-variables/m-p/803387#M316326</link>
    <description>&lt;P&gt;Try eliminating the quotes in the %INDEX function. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF %INDEX(&amp;amp;TAB., SHARED) &amp;gt; 0 %THEN %DO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, eliminate the quotes around SHARED_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables don't need to be tested against strings that have quotes around them, in fact, it is almost always the wrong thing to do.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37814"&gt;@Walternate&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Never tell us it didn't work and provide no other details. From now on, when code doesn't work, we need to see the LOG, and if the output is wrong, then show us the output and explain why it is incorrect.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2022 16:43:38 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-03-22T16:43:38Z</dc:date>
    <item>
      <title>Use macro value to conditionally print variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-value-to-conditionally-print-variables/m-p/803384#M316324</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a PROC PRINT, and the set of variables to be output is based on the value of a macro variable called tab (the print is outputting sheets to an Excel file). Basically, if tab starts with Shared_, a certain variable should be printed, but that variable should not be output for any tab that doesn't start with Shared_.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Previously, I set up something to output or not based on a specific tab name, and this worked perfectly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC PRINT DATA=HAVE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; VAR V1 V2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %IF &amp;amp;TAB. = ABC %THEN %DO;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;V3&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V4 V5;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IE, V3 would be print for the ABC tab and not any others.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, now, instead of a specific tab name, I have tab characteristics which apply to multiple tabs (begins with shared_). I have tried setting it up similarly as above but using index, and then substr, but neither will work for me:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC PRINT DATA=HAVE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; VAR V1 V2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %IF %INDEX(&amp;amp;TAB., 'SHARED') &amp;gt; 0 %THEN %DO;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;V3&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V4 V5;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;PROC PRINT DATA=HAVE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; VAR V1 V2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %IF %SUBSTR(&amp;amp;TAB., 1, 7) = 'SHARED_' %THEN %DO;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;V3&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V4 V5;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is much appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 16:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-value-to-conditionally-print-variables/m-p/803384#M316324</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2022-03-22T16:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use macro value to conditionally print variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-macro-value-to-conditionally-print-variables/m-p/803387#M316326</link>
      <description>&lt;P&gt;Try eliminating the quotes in the %INDEX function. Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF %INDEX(&amp;amp;TAB., SHARED) &amp;gt; 0 %THEN %DO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, eliminate the quotes around SHARED_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables don't need to be tested against strings that have quotes around them, in fact, it is almost always the wrong thing to do.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37814"&gt;@Walternate&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Never tell us it didn't work and provide no other details. From now on, when code doesn't work, we need to see the LOG, and if the output is wrong, then show us the output and explain why it is incorrect.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 16:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-macro-value-to-conditionally-print-variables/m-p/803387#M316326</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-22T16:43:38Z</dc:date>
    </item>
  </channel>
</rss>

