<?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: Macros in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425445#M27406</link>
    <description>&lt;P&gt;I suspect you made some typo's in transcribing the code, can you please verify it?&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jan 2018 23:27:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-01-05T23:27:16Z</dc:date>
    <item>
      <title>Macros</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425440#M27404</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm reading the text book 'SAS certification prep guide Advanced programming for sas9' and in chapter 12 it has this macro which I'm having trouble comprehending.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro prtlast;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;%if &amp;amp;syslast ne _NULL_ %the %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;proc print data=syslast(obs=5);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; title "Listing of &amp;amp;syslast data set";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; %put No data set has been created yet.;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=sasuser.courses out=bydays;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;by days;&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%prtlast;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I don't understand is why there is no &amp;amp;prtlast? and why prtlast is not set = to anything? where is the syslast macro come from? Why can you not just use a %let prtlast = 'work.dataset';?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help explaining what is happening with this macro would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 23:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425440#M27404</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2018-01-05T23:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425443#M27405</link>
      <description>&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n18mk1d0g1j31in1q6chazvfseel.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n18mk1d0g1j31in1q6chazvfseel.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SYSLAST is an automatic macro variable. It's for when you want to automatically reference the last data set used by default.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 23:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425443#M27405</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-05T23:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425445#M27406</link>
      <description>&lt;P&gt;I suspect you made some typo's in transcribing the code, can you please verify it?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 23:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425445#M27406</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-05T23:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425461#M27409</link>
      <description>&lt;P&gt;&amp;amp;prtlast would reference a single macro named prlast.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have defined macro programming with the %Macro prtlast ....&lt;/P&gt;
&lt;P&gt;Such code is called for execution using the %macronameonthemacrodefinition; reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose of macro code is often to automate an action. In this case to print the last used dataset (condition on one has been used in the current session).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let prtlast = 'work.dataset'; would only assign the text "work.dataset" to a variable, it would not actually print anything. AND using that macro variable in proc print such as&lt;/P&gt;
&lt;P&gt;proc print data=&amp;amp;prtlast;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;will generate errors.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jan 2018 00:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425461#M27409</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-06T00:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425465#M27410</link>
      <description>&lt;P&gt;You are getting confused between the difference between a macro variable and an actual macro.&amp;nbsp; It is not helpful that many places will frequently use "macro" when they really mean "macro variable".&amp;nbsp; A macro variable is a name that stores a string of characters.&amp;nbsp; A macro is an executable program that you can call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp; is used as a trigger to indicate to the macro processor that the name of a macro variable follows.&amp;nbsp; To execute a macro you need to use the % to trigger to the macro processor that the name of a macro you want to call will follow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The most common way to define a macro variable is to use a %LET statement. In a %LET statement you need to follow the name of the macro variable to be defined by an equal sign and then the value to be assigned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You use the %MACRO statement to define a macro.&amp;nbsp; The name of the macro to be defined follows the %MACRO keyword in the statement.&amp;nbsp; The %MEND statement marks the end of the macro definition.&amp;nbsp; A macro definition can include many statements including conditional statements like %IF and %DO that you cannot use in "open" SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro variable SYSLAST is an example of an automatic macro variable that SAS will create.&amp;nbsp; Other examples you should know about would include the SYSDATE, SYSDATE9 and SYSTIME macro variables that will be set when your SAS session starts.&amp;nbsp; These are all examples of automatic macro variables that will always exist.&amp;nbsp; There are also other automatic macro variables that will be created based on the code that you run.&amp;nbsp; For example the SQLOBS macro variable will get set when you run a SELECT statement inside of a PROC SQL step.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jan 2018 00:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425465#M27410</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-06T00:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425614#M27411</link>
      <description>&lt;P&gt;Ok thanks guys I get it. So is the %macro prtlast; part of the code so they can execute the %if functions outside the data step or because they want to use &amp;amp;SYSLAST? Basically to use an automatic Macro variable are you required to declare the macro step?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jan 2018 18:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425614#M27411</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2018-01-07T18:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macros</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425619#M27412</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;Basically to use an automatic Macro variable are you required to declare the macro step?&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No. You can use an automatic variable outside of a macro, but this macro is using conditional logic to only execute certain PROCs or Data steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if the data set didn't exist using a standard PROC PRINT would create an error in your log. Using this code means that it checks if the data set exists and then print it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Logic:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Check if a data set has been created, if it does:
&lt;OL&gt;
&lt;LI&gt;prints the data set&lt;/LI&gt;
&lt;LI&gt;If it doesn't, it prints a message to the log saying the data set doesn't exist.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this the only way to accomplish this type of logic, No. There are many ways to do things in SAS, and this is just one way to execute conditional logic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jan 2018 20:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Macros/m-p/425619#M27412</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-07T20:04:26Z</dc:date>
    </item>
  </channel>
</rss>

