<?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: Help with macro masking / quoting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591169#M169311</link>
    <description>&lt;P&gt;You appear to be asking two questions. One is how to handle an optional parameter. Second how to make it easier to pass in complex strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general I find that %LENGTH() is a good way to test if the parameter is set.&amp;nbsp; You can "fool" it by use %STR( ) to send in a non-empty string that only contains blanks.&amp;nbsp; If that is a concern look at this classic paper by Chung and King that tests many different ways of testing if a macro variable is "blank".&amp;nbsp;&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings09/022-2009.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings09/022-2009.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For passing values for this problem you might be able to use SYSPBUFF.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But perhaps it is just easier to tell the users to add parentheses around the values.&amp;nbsp; Extra parentheses will not hurt the logic of your generated WHERE clause.&amp;nbsp; Although they could still break your earlier test for empty values by passing in parentheses with nothing between them.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Sep 2019 14:37:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-09-24T14:37:33Z</dc:date>
    <item>
      <title>Help with macro masking / quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591109#M169284</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Can someone please help me quote / mask the below so that it works with all options.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Basically, I want to allow the use to filter the dataset using any SAS condition, so they could enter double quotes, single quotes, OR, = etc.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;Is there any way where there is no need to mask while calling the macro?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; testdata;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; account_status $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;20&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; marker $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; prod_type &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; account_status=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"Current"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; prod_type = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; marker=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; account_status=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"30days"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; prod_type = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; marker=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; account_status=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"60days"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; prod_type = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; marker=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; account_status=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"90days"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; prod_type = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; marker=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mymacro(param1= );&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data accounts_data ;&lt;/P&gt;
&lt;P&gt;set testdata (where = (MISSING(marker)&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;param1."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NE &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;""&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; AND (&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;param1.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mymacro;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;/* P1 PD Stability Volume - Volume By PD Pillar 1 Bands (Scored Segments Only) */&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;%&lt;STRONG&gt;&lt;I&gt;mymacro&lt;/I&gt;&lt;/STRONG&gt;(param1 = (account_status ^= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"Current"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; and prod_type ^= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;%&lt;STRONG&gt;&lt;I&gt;mymacro&lt;/I&gt;&lt;/STRONG&gt;(param1 = (prod_type ^= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;);&lt;/P&gt;
&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;mymacro&lt;/I&gt;&lt;/STRONG&gt;(param1 =&lt;/P&gt;
&lt;P&gt;);&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 08:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591109#M169284</guid>
      <dc:creator>Sanjay_M</dc:creator>
      <dc:date>2019-09-24T08:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macro masking / quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591113#M169288</link>
      <description>&lt;P&gt;What for? If they can write conditions, they can do the rest of the code anyway.&lt;/P&gt;
&lt;P&gt;Creating and maintaining such a macro (and the making of the calls) will be more effort than you could possibly save by using it.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 09:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591113#M169288</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-24T09:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macro masking / quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591114#M169289</link>
      <description>&lt;P&gt;Initially to get this working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, these will be then used by the development team to validate the outputs, so they may filter as needed. So I need to bring this in a position where this is working and not many changes are required.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 09:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591114#M169289</guid>
      <dc:creator>Sanjay_M</dc:creator>
      <dc:date>2019-09-24T09:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macro masking / quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591131#M169299</link>
      <description>This will handle most cases:&lt;BR /&gt;&lt;BR /&gt;%if %length(&amp;amp;param1.) %then and (&amp;amp;param1.);</description>
      <pubDate>Tue, 24 Sep 2019 11:12:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591131#M169299</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-09-24T11:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macro masking / quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591145#M169305</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/494"&gt;@Sanjay_M&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Read this article by Susan O'Conor:&amp;nbsp;&lt;A href="https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf" target="_blank"&gt;https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will explain you everything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 12:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591145#M169305</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-09-24T12:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macro masking / quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591169#M169311</link>
      <description>&lt;P&gt;You appear to be asking two questions. One is how to handle an optional parameter. Second how to make it easier to pass in complex strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general I find that %LENGTH() is a good way to test if the parameter is set.&amp;nbsp; You can "fool" it by use %STR( ) to send in a non-empty string that only contains blanks.&amp;nbsp; If that is a concern look at this classic paper by Chung and King that tests many different ways of testing if a macro variable is "blank".&amp;nbsp;&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings09/022-2009.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings09/022-2009.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For passing values for this problem you might be able to use SYSPBUFF.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But perhaps it is just easier to tell the users to add parentheses around the values.&amp;nbsp; Extra parentheses will not hurt the logic of your generated WHERE clause.&amp;nbsp; Although they could still break your earlier test for empty values by passing in parentheses with nothing between them.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 14:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591169#M169311</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-24T14:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macro masking / quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591178#M169316</link>
      <description>Very good reading!</description>
      <pubDate>Tue, 24 Sep 2019 14:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-macro-masking-quoting/m-p/591178#M169316</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-09-24T14:59:41Z</dc:date>
    </item>
  </channel>
</rss>

