<?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 Decoding macro code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195106#M36705</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;%macro&lt;/SPAN&gt;&lt;EM&gt; &lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;FileExist&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%if&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;(fileexist(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;InPath_Core.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;amp;InFileName))&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%then&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp; x rm&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: purple; font-size: 10pt;"&gt;"&amp;amp;InPath_Core.&amp;amp;InFileName."&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt;&lt;STRONG style="color: black; font-size: 10pt; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;FileExist&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 10pt; font-family: 'Courier New';"&gt;I just inherited a report that includes the above named code.&amp;nbsp; I believe the x rm is referencing a string variable to be used later in the report.&amp;nbsp; Is there a best practices method of decoding when not quite sure as to what a macro code sequence is doing?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 May 2015 14:09:25 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2015-05-28T14:09:25Z</dc:date>
    <item>
      <title>Decoding macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195106#M36705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;%macro&lt;/SPAN&gt;&lt;EM&gt; &lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;FileExist&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%if&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;(fileexist(&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;InPath_Core.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;amp;InFileName))&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;%then&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp; x rm&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: purple; font-size: 10pt;"&gt;"&amp;amp;InPath_Core.&amp;amp;InFileName."&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt;&lt;STRONG style="color: black; font-size: 10pt; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt; &lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;FileExist&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 10pt; font-family: 'Courier New';"&gt;I just inherited a report that includes the above named code.&amp;nbsp; I believe the x rm is referencing a string variable to be used later in the report.&amp;nbsp; Is there a best practices method of decoding when not quite sure as to what a macro code sequence is doing?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 14:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195106#M36705</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2015-05-28T14:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195107#M36706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The x rm has nothing to do with macro language.&amp;nbsp; X is the system command function which passes system commands through to the operating system.&amp;nbsp; RM is a dos command function remove.&amp;nbsp; What you code there is doing is:&lt;/P&gt;&lt;P&gt;Does this file xyz exist&lt;/P&gt;&lt;P&gt;If yes then remove the file xyz&lt;/P&gt;&lt;P&gt;return.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Personally I feel its quite dangerous to do this, if your macro resolves incorrectly you could erase whole directories or the wrong file etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 14:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195107#M36706</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-05-28T14:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195108#M36707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is an example of a questionable practice: assuming a variable not passed as a parameter.&lt;/P&gt;&lt;P&gt;The referenced code is either called within another macro that sets values for the two macro variables &amp;amp;InPathCore and &amp;amp;InFileName OR before this macro is used there should be two %let statements assigning values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case it looks like the code is to remove a file if it exists. The macro variables better be defined before the %FileExist is executed. Not the best name for a macro, DeleteFileExist might be better as Delete is the action performed.&lt;/P&gt;&lt;P&gt;Best practice is to provide a comment in the code as to what the macro accomplishes. If it modifies the values of variables created elsewhere it is a good idea to document that as well. In the case of "mystery" variables such as used here it may not be a bad idea to say where they are defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS documentation will get you as far use of such items as the %sysfunc, FileExist and X statements. Once you see X then you need to go to the operating system or other programs as X provides the ability to run system commands including other programs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 14:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195108#M36707</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-05-28T14:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195109#M36708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The most important step to take is to learn more SAS.&amp;nbsp; That might include the X command, but could include virtually any SAS pieces.&amp;nbsp; Remember, macro language doesn't process your data.&amp;nbsp; It merely generates the program that processes your data.&amp;nbsp; So the more you know about the programming language itself the better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The next most important step would be to learn more macro language.&amp;nbsp; To address your original question, learn about the options MPRINT, SYMBOLGEN, and MLOGIC.&amp;nbsp; Learning how and when to turn them on/off will help you view the generated SAS program as well as the macro language logic used to produce that program.&amp;nbsp; With more macro language knowledge, for example, you might notice that the macro you posted contains a flaw.&amp;nbsp; It is missing a semicolon that would end the X statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another tool that might help in decoding is the MFILE option.&amp;nbsp; It would let you store the generated SAS program in a file that you designate so you can examine it with all the macro language stripped away.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are few shortcuts.&amp;nbsp; Much of this is a long-term learning process.&amp;nbsp; Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 18:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195109#M36708</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-05-28T18:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Decoding macro code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195110#M36709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;a better name and parameter might be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro delete_if_exist(filename=)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then the action is obvious and easy to read&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%delete_if_exist(filename=&lt;SPAN style="font-family: 'Segoe UI','sans-serif'; color: black; font-size: 10pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: teal; font-size: 10pt;"&gt;InPath_Core.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;amp;InFileName)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 10pt; font-family: 'Courier New';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 10pt; font-family: 'Courier New';"&gt;Ron Fehd&amp;nbsp; readability maven&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 May 2015 17:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Decoding-macro-code/m-p/195110#M36709</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-05-29T17:42:53Z</dc:date>
    </item>
  </channel>
</rss>

