<?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: I need explanation for this code and the macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476574#M122658</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The macro program is very straightforward and if you have studied the Macro Language, then it should be very easy to read the macro program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; In pseudo-code:&lt;/P&gt;
&lt;P&gt;If the value of macro variable &amp;amp;date2 is GE 14610 then issue an options statement for YEARCUTOFF=2000&lt;/P&gt;
&lt;P&gt;else If the value of macro variable &amp;amp;date2 is LT 14610 then issue an options statement for YEARCUTOFF=1900&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The %MACRO/%MEND is causing the macro program Y2KOPT to be compiled and stored until it is ready to be used. The macro is defined as having 1 positional parameter named DATE2 and referred to in the macro program as &amp;amp;DATE2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The program starts with an OPTIONS statement that initially sets YEARCUTOFF to 1950, but that is really a distractor, as is the other OPTIONS statement that sets YEARCUTOFF to 1920.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The %LET statement that is outside the macro definition program creates a Global Macro variable called &amp;amp;DATE with a value of 14610 (and the question tells you that this value 14610, when it represents a date is the SAS date for January 1, 2000, which is nice to know, but the macro program uses the numeric value).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The macro program is invoked with the statement:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#003399"&gt; %y2kopt(&amp;amp;date)&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;and that means it is essentially the same as having:&lt;/P&gt;
&lt;P&gt;%y2kopt(14610)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which means that the parameter &amp;amp;DATE2 will hold the value 14610. So, the %IF test will be true and the first OPTIONS statement in the macro program will be sent for execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can prove this to yourself by using some debugging techniques like MPRINT/SYMBOLGEN and using %PUT along with testing the value of YEARCUTOFF at every step along the way, as shown below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yearcutoff.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21663i572631E3CC5E9767/image-size/large?v=v2&amp;amp;px=999" role="button" title="yearcutoff.png" alt="yearcutoff.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jul 2018 19:18:26 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2018-07-09T19:18:26Z</dc:date>
    <item>
      <title>I need explanation for this code and the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476561#M122655</link>
      <description>&lt;PRE&gt;&lt;FONT color="#003399"&gt;     options yearcutoff=1950;
     
     %macro y2kopt(date2);
        %if &amp;amp;date2 &amp;gt;= 14610 %then %do;
           options yearcutoff=2000;
        %end;
        %else %do;
           options yearcutoff=1900;
        %end;
     %mend;

     %let date=14610;
     options yearcutoff=1920;

     %y2kopt(&amp;amp;date)&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;The SAS date for January 1, 2000, is 14610. What is the value of YEARCUTOFF when the macro&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Y2kopt&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;finishes execution?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;EM&gt;a.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;1900&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;EM&gt;b.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;1920&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;EM&gt;c.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;1950&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;EM&gt;d.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;EM&gt;2000&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 09 Jul 2018 18:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476561#M122655</guid>
      <dc:creator>mona4u</dc:creator>
      <dc:date>2018-07-09T18:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: I need explanation for this code and the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476571#M122657</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134228"&gt;@mona4u&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;FONT color="#003399"&gt;     options yearcutoff=1950;
     
     %macro y2kopt(date2);
        %if &amp;amp;date2 &amp;gt;= 14610 %then %do;
           options yearcutoff=2000;
        %end;
        %else %do;
           options yearcutoff=1900;
        %end;
     %mend;

     %let date=14610;
     options yearcutoff=1920;

     %y2kopt(&amp;amp;date)&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The SAS date for January 1, 2000, is 14610. What is the value of YEARCUTOFF when the macro&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Y2kopt&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;finishes execution?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;EM&gt;a.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;EM&gt;1900&lt;/EM&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;EM&gt;b.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;EM&gt;1920&lt;/EM&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;EM&gt;c.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;EM&gt;1950&lt;/EM&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;EM&gt;d.&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;EM&gt;2000&lt;/EM&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try it.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 19:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476571#M122657</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-09T19:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: I need explanation for this code and the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476574#M122658</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The macro program is very straightforward and if you have studied the Macro Language, then it should be very easy to read the macro program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; In pseudo-code:&lt;/P&gt;
&lt;P&gt;If the value of macro variable &amp;amp;date2 is GE 14610 then issue an options statement for YEARCUTOFF=2000&lt;/P&gt;
&lt;P&gt;else If the value of macro variable &amp;amp;date2 is LT 14610 then issue an options statement for YEARCUTOFF=1900&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The %MACRO/%MEND is causing the macro program Y2KOPT to be compiled and stored until it is ready to be used. The macro is defined as having 1 positional parameter named DATE2 and referred to in the macro program as &amp;amp;DATE2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The program starts with an OPTIONS statement that initially sets YEARCUTOFF to 1950, but that is really a distractor, as is the other OPTIONS statement that sets YEARCUTOFF to 1920.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The %LET statement that is outside the macro definition program creates a Global Macro variable called &amp;amp;DATE with a value of 14610 (and the question tells you that this value 14610, when it represents a date is the SAS date for January 1, 2000, which is nice to know, but the macro program uses the numeric value).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The macro program is invoked with the statement:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#003399"&gt; %y2kopt(&amp;amp;date)&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;and that means it is essentially the same as having:&lt;/P&gt;
&lt;P&gt;%y2kopt(14610)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which means that the parameter &amp;amp;DATE2 will hold the value 14610. So, the %IF test will be true and the first OPTIONS statement in the macro program will be sent for execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can prove this to yourself by using some debugging techniques like MPRINT/SYMBOLGEN and using %PUT along with testing the value of YEARCUTOFF at every step along the way, as shown below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yearcutoff.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21663i572631E3CC5E9767/image-size/large?v=v2&amp;amp;px=999" role="button" title="yearcutoff.png" alt="yearcutoff.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 19:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476574#M122658</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-07-09T19:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: I need explanation for this code and the macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476575#M122659</link>
      <description>&lt;P&gt;I would recommend reading this book&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/store/books/categories/usage-and-reference/carpenter-s-complete-guide-to-the-sas-macro-language-third-edition/prodBK_67815_en.html" target="_blank"&gt;https://www.sas.com/store/books/categories/usage-and-reference/carpenter-s-complete-guide-to-the-sas-macro-language-third-edition/prodBK_67815_en.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then I bet your understanding would be spot on!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 19:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-explanation-for-this-code-and-the-macro/m-p/476575#M122659</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2018-07-09T19:20:34Z</dc:date>
    </item>
  </channel>
</rss>

