<?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: Macro Parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451135#M113685</link>
    <description>The isblank macro is not part of the base sas language so it must probably be user defined. Without the code, it is not possible to answer your question.</description>
    <pubDate>Wed, 04 Apr 2018 15:00:31 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2018-04-04T15:00:31Z</dc:date>
    <item>
      <title>Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451115#M113675</link>
      <description>&lt;P&gt;I am not able to resolve the cause of the error. Can someone please help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chk(where=);
	%if %isblank(%nrstr(&amp;amp;where.))=0 %then
		%do;
			%if %upcase(%substr(%str(&amp;amp;where.),1,5)) ne WHERE %then
				%do;
					%put %str(E)RROR: "Please put WHERE at the starting of the where macro parameter.";
					%return;
				%end;
		%end;
%mend;
options symbolgen mprint mlogic;
%chk(where=where);/*It works as Expected*/
%chk();/*It does NOT work as Expected. I want the first condition to turn to false for this case.*/

/*Also tried this*/
%macro chk(where=);
	%if not %isblank(%nrstr(&amp;amp;where.)) %then
		%do;
			%if %upcase(%substr(%str(&amp;amp;where.),1,5)) ne WHERE %then
				%do;
					%put %str(E)RROR: "Please put WHERE at the starting of the where macro parameter.";
					%return;
				%end;
		%end;
%mend;
%chk(where=where);/*It works as Expected*/
%chk();/*It does NOT work as Expected. I want the first condition to turn to false for this case.*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Apr 2018 14:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451115#M113675</guid>
      <dc:creator>arpitsharma27</dc:creator>
      <dc:date>2018-04-04T14:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451125#M113679</link>
      <description>Hello, &lt;BR /&gt;&lt;BR /&gt;In your second call, &amp;amp;where. is an empty string so you can't extract the first five characters (the log displays an error). You can check length prior to the substring extraction or add characters to ensure that your string is at least 5 characters long :&lt;BR /&gt;%if %upcase(%substr(%str(&amp;amp;where.12345),1,5)) ne WHERE</description>
      <pubDate>Wed, 04 Apr 2018 14:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451125#M113679</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-04-04T14:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451128#M113681</link>
      <description>&lt;P&gt;So I see your point in helping me resolve the issue here.-- By using %length and determining the macro variable. And it does solve my problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But why is the first condition not resolving to FALSE.?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 14:55:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451128#M113681</guid>
      <dc:creator>arpitsharma27</dc:creator>
      <dc:date>2018-04-04T14:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451129#M113682</link>
      <description>&lt;P&gt;Your macro statement is defined by keyword parameter and your trying to invoke it with not parameters, then default values will be applied (%chk(); or %chk; then will be resolved as %chk(where=);&amp;nbsp; )&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 14:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451129#M113682</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-04T14:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451135#M113685</link>
      <description>The isblank macro is not part of the base sas language so it must probably be user defined. Without the code, it is not possible to answer your question.</description>
      <pubDate>Wed, 04 Apr 2018 15:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451135#M113685</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-04-04T15:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451151#M113692</link>
      <description>&lt;P&gt;Using = or just listing parameter is two different ways of defining a macro ie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro myMacro(var1= , var2=);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is different than:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro myMacro(var1, var2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;They're both valid, but different definitions. For example, in the first one the order of the parameters doesn't matter when you call it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro myMacro(var1=, var2=);

proc print data=sashelp.class (obs=3);
var &amp;amp;var1 &amp;amp;var2;
run;

%mend;

%mymacro(var1=age, var2=name);
%mymacro(var2=name, var1=age);
%mymacro(var1=name, var2=age);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But whatever option you pick, you must stick with it. In your question above, you're mixing styles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 15:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451151#M113692</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-04T15:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451198#M113712</link>
      <description>&lt;P&gt;I'd suggest getting rid of %ISBLANK and just checking for&amp;nbsp; a null value in a simple way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %length(&amp;amp;where.) &amp;gt; 0 %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At least that's what I assume %ISBLANK is supposed to be doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect the problem is from the use of %NRSTR that could prevent resolution of &amp;amp;WHERE. (but I can't check that right now).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, it looks like %STR does nothing when encased within %UPCASE and %SUBSTR.&amp;nbsp; I would remove %STR from that line of code.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 16:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451198#M113712</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-04T16:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451211#M113719</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a macro that will add the keyword WHERE to the beginning if the value does not already start with the word WHERE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chk(where);
%if %length(&amp;amp;where) %then %do;
%if "WHERE " ne "%qsubstr(%qupcase(&amp;amp;where) 12345,1,6)" %then
   %let where=where &amp;amp;where
;
%end;
%put &amp;amp;=where ;
%mend;

%chk();
%chk(fred);
%chk(wherefred);
%chk(where age&amp;gt;10);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The normal ISBLANK macro I have seen tests if the value is empty or only contains spaces. I normally just use %LENGTH() to test if the string is empty.&amp;nbsp; To see the difference try calling the test macro with a macro quoted blanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%chk(%str( ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you can defined the parameter as positional so that you can call the macro without listing the parameter name.&amp;nbsp; But you can still call it using the keyword if you want.&amp;nbsp; You just can't call by position when the parameter is defined as keyword.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%chk(where=where age&amp;gt;10);
%chk(where=age&amp;gt;10);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example results:&lt;/P&gt;
&lt;PRE&gt;88   %chk();
WHERE=
89   %chk(fred);
WHERE=where fred
90   %chk(wherefred);
WHERE=where wherefred
91   %chk(where age&amp;gt;10);
WHERE=where age&amp;gt;10
92   %chk(%str( ));
WHERE=where
93   %chk(where=where age&amp;gt;10);
WHERE=where age&amp;gt;10
94   %chk(where=age&amp;gt;10);
WHERE=where age&amp;gt;10&lt;/PRE&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>Wed, 04 Apr 2018 17:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter/m-p/451211#M113719</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-04T17:08:43Z</dc:date>
    </item>
  </channel>
</rss>

