<?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: why %if %then does not work? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56944#M12204</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro is a text processing facility and so you don't quote character strings. Plus it need not run in a data step. See:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let c=yes;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let d=yes;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %symlocal(c) %then %put **** c a is local;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %else %put **** c is global;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also note that sumlocal is both a macro function and not a data step function. So you need to use %symlocal when running it as macro code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are new to macro I would suggest that you do a Google search for any papers by Ian Whitlock on the macro facility. His papers do a great job of explaining the background behind why what you tried did not work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Apr 2012 14:22:13 GMT</pubDate>
    <dc:creator>DonH</dc:creator>
    <dc:date>2012-04-06T14:22:13Z</dc:date>
    <item>
      <title>why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56943#M12203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a macro program, if, then statement, you have to use %if %then&lt;/P&gt;&lt;P&gt;but following macro program it says:&lt;/P&gt;&lt;P&gt;ERROR: Required operator not found in expression: symlocal('c')&lt;/P&gt;&lt;P&gt;ERROR: The macro TEST will stop executing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rather, if, then statement works,&lt;/P&gt;&lt;P&gt;I can't wrap my head around it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let c=yes;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let d=yes;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %if symlocal('c') %then %put '**** c a is local';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %else %put '**** c is global';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if symlocal ('d') then put '**** d is local';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else put '**** d is global';&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 13:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56943#M12203</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-04-06T13:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56944#M12204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro is a text processing facility and so you don't quote character strings. Plus it need not run in a data step. See:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let c=yes;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let d=yes;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %symlocal(c) %then %put **** c a is local;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %else %put **** c is global;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also note that sumlocal is both a macro function and not a data step function. So you need to use %symlocal when running it as macro code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are new to macro I would suggest that you do a Google search for any papers by Ian Whitlock on the macro facility. His papers do a great job of explaining the background behind why what you tried did not work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2012 14:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56944#M12204</guid>
      <dc:creator>DonH</dc:creator>
      <dc:date>2012-04-06T14:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56945#M12205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, it confuses me because I don't know how to tell if it is macro variable or data step variable.&lt;/P&gt;&lt;P&gt;The example in my question is from: &lt;A href="http://www2.sas.com/proceedings/sugi31/107-31.pdf" title="http://www2.sas.com/proceedings/sugi31/107-31.pdf"&gt;http://www2.sas.com/proceedings/sugi31/107-31.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;originally it is written like this:&lt;/P&gt;&lt;P&gt;%let c=yes;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%let d=yes;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if symlocal('c') then put '**** c a is local';&lt;/P&gt;&lt;P&gt;else put '**** c is global';&lt;/P&gt;&lt;P&gt;if symlocal ('d') then put '**** d is local';&lt;/P&gt;&lt;P&gt;else put '**** d is global';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so, you see, c and d are quoted in the symlocal function, and in the macro, %if %then statement are not used but only if then, it confuses me.&lt;/P&gt;&lt;P&gt;Can someone help explain?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 04:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56945#M12205</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-04-07T04:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56946#M12206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, unless you changed the original, you had them mixed (i.e., used symlocal once and %symlocal once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree with Don that Ian's papers would be a good way to start.&amp;nbsp; If you are serious about wanting to learn, I have a spreadsheet that contains links to all of his SAS-L posts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the meantime, here is a different mixture that all work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let c=yes;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let d=yes;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if %symlocal(c) %then %put '**** c a is local';&lt;/P&gt;&lt;P&gt;&amp;nbsp; %else %put '**** c is global';&lt;/P&gt;&lt;P&gt;&amp;nbsp; data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if %symlocal(c) %then %put '**** c a is local';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %put '**** c is global';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if symlocal ('d') then put '**** d is local';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else put '**** d is global';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 13:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56946#M12206</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-04-07T13:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56947#M12207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Art297,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please share the links you have? I really love to check it out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 16:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56947#M12207</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-04-07T16:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56948#M12208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Send me an email at atabachneck at gmail dot com.&amp;nbsp; I can't post it here because Ian never gave me permission to post it on the web.&amp;nbsp; I wish he would, because there are numerous gold nuggets in those posts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 16:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56948#M12208</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-04-07T16:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56949#M12209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you going to email me too if I ask for it?&amp;nbsp;&amp;nbsp; Thanks - Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 17:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56949#M12209</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-04-07T17:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56950#M12210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure, just send me an email.&amp;nbsp; I don't have any problem sharing the spreadsheet, I just don't feel comfortable putting it on the web without Ian's permission.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 17:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56950#M12210</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-04-07T17:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56951#M12211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you! I just emailed you.&amp;nbsp;&amp;nbsp; - Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 17:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56951#M12211</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-04-07T17:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: why %if %then does not work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56952#M12212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fantastic, I just sent an email to you, really appreciate your help, Art&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2012 19:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-if-then-does-not-work/m-p/56952#M12212</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2012-04-07T19:26:28Z</dc:date>
    </item>
  </channel>
</rss>

