<?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: Problem with PROC SQL Macro If in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432102#M106960</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You do not have a closing semicolon after end of SQL statement&lt;/LI&gt;&lt;LI&gt;You have a open and statement condition in the query.&lt;/LI&gt;&lt;LI&gt;Please follow the answer provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, It is the most effective way of doing it.&lt;/LI&gt;&lt;LI&gt;Please check the macro variable&amp;nbsp;&lt;SPAN&gt;&amp;amp;TYPE, most of the time they are wrongly entered with quotation attached ('Y' insted of Y) that fails both condition in your macro if condition.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
...
where REPORT_VW.TYPE_GROUP_CD = "&amp;amp;TYPE";
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Jan 2018 08:35:25 GMT</pubDate>
    <dc:creator>Satish_Parida</dc:creator>
    <dc:date>2018-01-30T08:35:25Z</dc:date>
    <item>
      <title>Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/431997#M106916</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I'm trying to build where proc sql where clause&amp;nbsp;conditionally using a macro if/then and a macro variable (TYPE).&amp;nbsp; However, I can't seem to get it to evaluate right.&amp;nbsp; Here's the where clause:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%IF &amp;amp;TYPE = Y %THEN %DO;&lt;BR /&gt;REPORT_VW.TYPE_GROUP_CD = 'Y' AND&lt;BR /&gt;%END;&lt;BR /&gt;%IF &amp;amp;TYPE = S %THEN %DO;&lt;BR /&gt;REPORT_VW.TYPE_GROUP_CD = 'S' AND&lt;BR /&gt;%END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's wrong here?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 22:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/431997#M106916</guid>
      <dc:creator>yus03590</dc:creator>
      <dc:date>2018-01-29T22:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/431998#M106917</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;However, I can't seem to get it to evaluate right.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What does that mean? How are you setting the macro variable? What isn't working correctly, are you getting an error or incorrectly classified data? If incorrectly classified, does it appear random or is there some pattern?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any reason to not just do:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REPORT_VW.TYPE_GROUP_CD = "&amp;amp;TYPE" AND&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jan 2018 22:42:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/431998#M106917</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-29T22:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/431999#M106918</link>
      <description>&lt;P&gt;There's nothing wrong with the code you have shown.&amp;nbsp; But there are lots of possibilities that extend beyond what you have shown.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro %IF/%THEN statements can only appear inside a macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you have shown doesn't finish the WHERE clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll need to test the code making sure the MPRINT option is on, and show the log.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 22:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/431999#M106918</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-29T22:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432095#M106956</link>
      <description>&lt;P&gt;I think in %if &amp;amp;TYPE = Y and S should be in quote like 'Y' and 'S' .&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 08:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432095#M106956</guid>
      <dc:creator>prashantgupta</dc:creator>
      <dc:date>2018-01-30T08:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432102#M106960</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You do not have a closing semicolon after end of SQL statement&lt;/LI&gt;&lt;LI&gt;You have a open and statement condition in the query.&lt;/LI&gt;&lt;LI&gt;Please follow the answer provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;, It is the most effective way of doing it.&lt;/LI&gt;&lt;LI&gt;Please check the macro variable&amp;nbsp;&lt;SPAN&gt;&amp;amp;TYPE, most of the time they are wrongly entered with quotation attached ('Y' insted of Y) that fails both condition in your macro if condition.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
...
where REPORT_VW.TYPE_GROUP_CD = "&amp;amp;TYPE";
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2018 08:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432102#M106960</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-01-30T08:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432268#M107049</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108025"&gt;@prashantgupta&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I think in %if &amp;amp;TYPE = Y and S should be in quote like 'Y' and 'S' .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not in macro comparisons. Literals don't have quotes in functions either.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 15:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432268#M107049</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-30T15:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432497#M107130</link>
      <description>&lt;P&gt;So I'm trying to execute certain filters conditionally depending on the value of the macro TYPE variable, the value of which is set by a sas job web interface and is either Y, S or A.&amp;nbsp; The filtering conditions within the macro if are not evaluating even when TYPE = Y or S.&amp;nbsp; My final where clause outside the if is the only one being executed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understand correctly from all the comments, the correct format is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MACRO_NAME(TYPE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;%if &amp;amp;TYPE = Y %then %do;&lt;/P&gt;&lt;P&gt;person.age_group = Y AND&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;TYPE = S %then %do;&lt;/P&gt;&lt;P&gt;person.age_group = S AND&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;final sql condition;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%END&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**call the macro&lt;/P&gt;&lt;P&gt;MACRO_NAME(TYPE);&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 21:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432497#M107130</guid>
      <dc:creator>yus03590</dc:creator>
      <dc:date>2018-01-30T21:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432499#M107132</link>
      <description>&lt;P&gt;If I understand correctly, the correct format is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MACRO_NAME(TYPE);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;%if &amp;amp;TYPE = Y %then %do;&lt;/P&gt;&lt;P&gt;person.age_group = Y AND&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if &amp;amp;TYPE = S %then %do;&lt;/P&gt;&lt;P&gt;person.age_group = S AND&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;final sql condition;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%END&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**call the macro&lt;/P&gt;&lt;P&gt;MACRO_NAME(TYPE);&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 21:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432499#M107132</guid>
      <dc:creator>yus03590</dc:creator>
      <dc:date>2018-01-30T21:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with PROC SQL Macro If</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432530#M107142</link>
      <description>&lt;P&gt;In this more complete version of the program, you need quotes in the SQL code, but not in the macro comparisons:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;where&lt;/P&gt;
&lt;P&gt;%if &amp;amp;TYPE = Y %then %do;&lt;/P&gt;
&lt;P&gt;person.age_group = 'Y' AND&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;TYPE = S %then %do;&lt;/P&gt;
&lt;P&gt;person.age_group = 'S' AND&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;final sql condition;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, it looks like that final %END was intended to be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%MEND;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still, it would be a good idea to apply the earlier suggestion, as long as &amp;amp;TYPE will always be Y or S:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;where&lt;/P&gt;
&lt;P&gt;person.age_group = "&amp;amp;TYPE" AND&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;final sql condition;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be sure to use double quotes (not single quotes) .... necessary to allow &amp;amp;TYPE to resolve into its value.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 21:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-PROC-SQL-Macro-If/m-p/432530#M107142</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-30T21:56:31Z</dc:date>
    </item>
  </channel>
</rss>

