<?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 Macro parameter in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574248#M12663</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to pass macro parameters as shwon below where it can handle a straight assignment or a if statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test(var1=);&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;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test(var1=abc);&lt;/P&gt;&lt;P&gt;%test(var1= (if x=1 then var1='blah';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else var1='blah blah');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;);&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2019 15:57:25 GMT</pubDate>
    <dc:creator>SASPhile</dc:creator>
    <dc:date>2019-07-17T15:57:25Z</dc:date>
    <item>
      <title>Macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574248#M12663</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to pass macro parameters as shwon below where it can handle a straight assignment or a if statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test(var1=);&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;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test(var1=abc);&lt;/P&gt;&lt;P&gt;%test(var1= (if x=1 then var1='blah';&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else var1='blah blah');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;);&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 15:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574248#M12663</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2019-07-17T15:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574267#M12670</link>
      <description>I've often found it works to put double quotes around it and then remove them in the macro.  &lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;%test(var1="(if x=1 then var1='blah'; else var1='blah blah');" );&lt;BR /&gt;&lt;BR /&gt;Then use&lt;BR /&gt;%let newvar1=%qsysfunc(compress(&amp;amp;var1,%str(%")));&lt;BR /&gt;to remove the double-quotes.&lt;BR /&gt;</description>
      <pubDate>Wed, 17 Jul 2019 16:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574267#M12670</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2019-07-17T16:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574268#M12671</link>
      <description>&lt;P&gt;&lt;SPAN&gt;var1="(if x=1 then var1='blah'; else var1='blah blah');"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Isnt this double assignment for the same variable Var1 ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;="(if x=1 then &lt;STRONG&gt;var1&lt;/STRONG&gt;='blah'; else &lt;STRONG&gt;var1&lt;/STRONG&gt;='blah blah');"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 16:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574268#M12671</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2019-07-17T16:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574294#M12675</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;var1="(if x=1 then var1='blah'; else var1='blah blah');"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Isnt this double assignment for the same variable Var1 ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;="(if x=1 then &lt;STRONG&gt;var1&lt;/STRONG&gt;='blah'; else &lt;STRONG&gt;var1&lt;/STRONG&gt;='blah blah');"&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;NO.&amp;nbsp; The first use of VAR1 is the name of the macro parameter.&amp;nbsp; The second use depends on how &amp;amp;VAR1 is used in the macro, but most likely it is referencing a dataset variable named var1.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 17:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574294#M12675</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-17T17:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574296#M12676</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/144199"&gt;@tomrvincent&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I've often found it works to put double quotes around it and then remove them in the macro. &lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;%test(var1="(if x=1 then var1='blah'; else var1='blah blah');" );&lt;BR /&gt;&lt;BR /&gt;Then use&lt;BR /&gt;%let newvar1=%qsysfunc(compress(&amp;amp;var1,%str(%")));&lt;BR /&gt;to remove the double-quotes.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't use COMPRESS() as it will also remove any quotes that you want to keep.&amp;nbsp; Instead use DEQUOTE().&amp;nbsp; If the value is not enclosed in quotes then DEQUOTE() will not change it.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(dequote(&amp;amp;var1))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2019 17:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574296#M12676</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-17T17:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574299#M12677</link>
      <description>&lt;P&gt;It is the sem-colons that are going to cause trouble.&lt;/P&gt;
&lt;P&gt;You need to quote the value in the call and then remove the quoting when using the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either use macro quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(var1);
...
%unquote(&amp;amp;var1)
...
%mend test;
%test(var1=%str(if x=1 then var1='blah';else var1='blah blah';))
%test(var1=if x=1 then var1='blah'%str(;)else var1='blah blah'%str(;))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use you can use actual quotes.&amp;nbsp; Note that with this method you can call it with either macro quoting or actual quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(var1);
...
%sysfunc(dequote((&amp;amp;var1))
...
%mend test;
%test(var1="if x=1 then var1='blah';else var1='blah blah';")
%test(var1='if x=1 then var1="blah";else var1="blah blah";')
%test(var1='if x=1 then var1=''blah'';else var1=''blah blah'';')

%test(var1=%str(if x=1 then var1='blah';else var1='blah blah';))
%test(var1=if x=1 then var1='blah'%str(;)else var1='blah blah'%str(;))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2019 17:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574299#M12677</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-17T17:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574315#M12681</link>
      <description>Different 'variables'.&lt;BR /&gt;&lt;BR /&gt;Best to have different names for your macro variables and dataset columns.&lt;BR /&gt;&lt;BR /&gt;Maybe MacroVar1="(if x=1 then colvar1='blah'; else colvar1='blah blah');" would be better.</description>
      <pubDate>Wed, 17 Jul 2019 18:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter/m-p/574315#M12681</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2019-07-17T18:19:11Z</dc:date>
    </item>
  </channel>
</rss>

