<?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: How to test whether macro variable exist in macro if statement? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341045#M77987</link>
    <description>&lt;P&gt;You defined the macro as:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro extract(beginDate='01JAN2017'd, endDate='05JAN2017'd, cPvderVAR=);&lt;/PRE&gt;
&lt;P&gt;I understand that you want to check does the 2nd argument is not empty,&lt;/P&gt;
&lt;P&gt;then can use either&amp;nbsp;&lt;STRONG&gt;%if &amp;nbsp;&amp;amp;cPvderVAR NE &lt;/STRONG&gt;(without quotes)&amp;nbsp; &amp;nbsp;or &lt;STRONG&gt;&amp;nbsp;%if&amp;nbsp;%length(&amp;amp;cPvderVAR) &amp;gt; 0&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could alse use next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract(beginDate='01JAN2017'd,
	                        endDate='05JAN2017'd,
	                        cPvderVAR=);
%put &amp;amp;cPvderVAR.;
	data want_&amp;amp;cPvderVAR.;
		set have;
		%do;
			where dTran &amp;gt;= &amp;amp;beginDate. and dTran &amp;lt;= &amp;amp;endDate. 
                %end;
                %if &amp;amp;cPvderVAR. ne %then %do; 
                              and cPvder="&amp;amp;cPvderVAR."      /* changed to double quotes */ 
		%end;&lt;BR /&gt;                 ;    /* semicolon to close the where statement */
	run;
%mend extract;

%extract(cPvderVAR=PING);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2017 05:48:40 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-03-15T05:48:40Z</dc:date>
    <item>
      <title>How to test whether macro variable exist in macro if statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341031#M77982</link>
      <description>&lt;PRE&gt;%macro extract(beginDate='01JAN2017'd,
	                        endDate='05JAN2017'd,
	                        cPvderVAR=);
%put &amp;amp;cPvderVAR.;
	data want_&amp;amp;cPvderVAR.;
		set have;
		%if '&amp;amp;cPvderVAR.' ne %then %do; 
			where dTran &amp;gt;= &amp;amp;beginDate. and dTran &amp;lt;= &amp;amp;endDate. and cPvder='&amp;amp;cPvderVAR.' ;
		%end;
		%else %do;
			where dTran &amp;gt;= &amp;amp;beginDate. and dTran &amp;lt;= &amp;amp;endDate.;
		%end;
	run;
%mend extract;

%extract(cPvderVAR=PING);&lt;/PRE&gt;&lt;P&gt;Keep getting this error&lt;/P&gt;&lt;P&gt;WHERE 0 /* an obviously FALSE WHERE clause */ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is, if the macro variable cPvderVAR has a value then add the where statement with cPvder = &amp;amp;cPvderVAR.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that cPvder is a string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does SAS has something to test whether the macro variable is of length null or positive?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 02:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341031#M77982</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-15T02:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to test whether macro variable exist in macro if statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341045#M77987</link>
      <description>&lt;P&gt;You defined the macro as:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro extract(beginDate='01JAN2017'd, endDate='05JAN2017'd, cPvderVAR=);&lt;/PRE&gt;
&lt;P&gt;I understand that you want to check does the 2nd argument is not empty,&lt;/P&gt;
&lt;P&gt;then can use either&amp;nbsp;&lt;STRONG&gt;%if &amp;nbsp;&amp;amp;cPvderVAR NE &lt;/STRONG&gt;(without quotes)&amp;nbsp; &amp;nbsp;or &lt;STRONG&gt;&amp;nbsp;%if&amp;nbsp;%length(&amp;amp;cPvderVAR) &amp;gt; 0&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could alse use next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract(beginDate='01JAN2017'd,
	                        endDate='05JAN2017'd,
	                        cPvderVAR=);
%put &amp;amp;cPvderVAR.;
	data want_&amp;amp;cPvderVAR.;
		set have;
		%do;
			where dTran &amp;gt;= &amp;amp;beginDate. and dTran &amp;lt;= &amp;amp;endDate. 
                %end;
                %if &amp;amp;cPvderVAR. ne %then %do; 
                              and cPvder="&amp;amp;cPvderVAR."      /* changed to double quotes */ 
		%end;&lt;BR /&gt;                 ;    /* semicolon to close the where statement */
	run;
%mend extract;

%extract(cPvderVAR=PING);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 05:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341045#M77987</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-15T05:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to test whether macro variable exist in macro if statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341053#M77992</link>
      <description>&lt;P&gt;You can't use single quotes around a reference to a macro variable. &amp;nbsp;It won't resolve. &amp;nbsp;Try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro extract (beginDate='01JAN2017'd, endDate='05JAN2017'd, cPvderVar=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%put &amp;amp;cPvderVAR.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;data want_&amp;amp;cPvderVAR.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; where (&amp;amp;beginDate. &amp;lt;= dTran &amp;lt;= &amp;amp;endDate.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %if %length(&amp;amp;cPvderVar) %then and cPvder="&amp;amp;cPvderVAR.";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;%mend extract;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%extract(cPvderVAR=PING)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Switching to double quotes lets &amp;amp;cPvderVAR resolve. &amp;nbsp;The other changes aren't mandatory, just coding that makes it easier to see how the program changes when cPvderVAR is specified vs. not specified.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 03:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341053#M77992</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-15T03:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to test whether macro variable exist in macro if statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341062#M77994</link>
      <description>&lt;P&gt;That extra information about the single/double quote is helpful.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 04:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341062#M77994</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-15T04:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to test whether macro variable exist in macro if statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341085#M78002</link>
      <description>I was trying to factor the common condititions but couldn't work it out. I'm glad you helped with it as well :). Thanks.</description>
      <pubDate>Wed, 15 Mar 2017 06:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-test-whether-macro-variable-exist-in-macro-if-statement/m-p/341085#M78002</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-15T06:51:06Z</dc:date>
    </item>
  </channel>
</rss>

