<?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: Proc SQL With %IF %THEN Macro in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278356#M58878</link>
    <description>&lt;P&gt;Further ro what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt; already explained be careful withthe quotes around IND as the quotes become part of the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cntry='IND';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then the comparison&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;cntry=IND&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will always be false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your code is in danger of generating two consecutive AND keywords if the %if resolves to false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always run with at least when debugging macro statements. It will help take out the guesswork.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Sat, 18 Jun 2016 10:36:20 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-06-18T10:36:20Z</dc:date>
    <item>
      <title>Proc SQL With %IF %THEN Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278336#M58871</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to execute a proc sql based on a condition.&lt;/P&gt;&lt;P&gt;One where condition in proc sql should run only on certain condition. Need some help to get it resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any inputs or thoughts please ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--- Current Code ---&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table validate&lt;BR /&gt;as&lt;BR /&gt;select city,street,address,state_province_cd from master_table a master_table b&lt;BR /&gt;where a.city = b.city and a.state_province_cd = b.state_province_cd and a.address = b.address&lt;BR /&gt;group by city,street,address,state_province_cd;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--- New Code Required ---&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro validate;&lt;/P&gt;&lt;P&gt;%let cntry='IND';&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table validate&lt;BR /&gt;as&lt;BR /&gt;select city,street,address,state_province_cd from master_table a master_table b&lt;BR /&gt;where a.city = b.city and&lt;BR /&gt;%if %eval(&amp;amp;cntry. in IND ARG) %then %str (AND a.state_province_cd = b.state_province_cd)&lt;BR /&gt;and a.address = b.address&lt;BR /&gt;group by city,street,address,state_province_cd;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend validate;&lt;BR /&gt;%validate;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2016 05:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278336#M58871</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2016-06-18T05:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL With %IF %THEN Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278350#M58877</link>
      <description>&lt;P&gt;Remember your macro needs to resolve to valid SAS code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's no ELSE clause so if it doesnt execute what do you end up with, hint - check the number of ANDs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your IF condition appears to be incorrect and should include values in brackets, %eval.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2016 09:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278350#M58877</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-18T09:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL With %IF %THEN Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278356#M58878</link>
      <description>&lt;P&gt;Further ro what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt; already explained be careful withthe quotes around IND as the quotes become part of the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cntry='IND';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then the comparison&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;cntry=IND&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will always be false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also your code is in danger of generating two consecutive AND keywords if the %if resolves to false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always run with at least when debugging macro statements. It will help take out the guesswork.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2016 10:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278356#M58878</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-18T10:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL With %IF %THEN Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278457#M58896</link>
      <description>&lt;P&gt;For better readability, I keep macro code and SAS Base code in separate lines, like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if condition %then %do;
base SAS code
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This makes sure I put semicolons etc. where needed.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 07:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278457#M58896</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-19T07:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL With %IF %THEN Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278472#M58900</link>
      <description>&lt;P&gt;You need to end the %IF statment with a semi-colon. &amp;nbsp;You need to make sure your macro variable matches the values you are testing against. &amp;nbsp;If the macro variable has quotes then &amp;nbsp;the values you are comparing it to need to have quotes also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro validate;

%let cntry=IND;

proc sql noprint;
  create table validate as
    select city,street,address,state_province_cd 
    from master_table a
       , master_table b
    where a.city = b.city 
      and a.address = b.address
%if %eval(&amp;amp;cntry. in IND ARG) %then 
      and a.state_province_cd = b.state_province_cd
; 
    group by city,street,address,state_province_cd
  ;
quit;
%mend validate;
%validate;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jun 2016 14:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278472#M58900</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-06-19T14:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL With %IF %THEN Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278482#M58902</link>
      <description>&lt;P&gt;Thanks for the 'AND' Tip!!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 15:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278482#M58902</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2016-06-19T15:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL With %IF %THEN Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278483#M58903</link>
      <description>&lt;P&gt;Thanks all for the inputs. Much appretiated!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So finally found what i was trying to do here!&amp;nbsp;&lt;A href="http://support.sas.com/kb/35/591.html" target="_blank"&gt;http://support.sas.com/kb/35/591.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Modified my code to something like this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;where a.city = b.city and&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;%if %eval(&amp;amp;cntry. in IND ARG) %then %str (a.state_province_cd = b.state_province_cd AND);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;a.address = b.address&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2016 15:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-With-IF-THEN-Macro/m-p/278483#M58903</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2016-06-19T15:30:51Z</dc:date>
    </item>
  </channel>
</rss>

