<?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: Create Marco variable when it's Monday skip back 3 day else skip 1 day. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76109#M16432</link>
    <description>Thanks, I read the section you pointed to and was able to create a global variable yesterday.  Thanks again!</description>
    <pubDate>Mon, 19 Oct 2009 12:47:20 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-10-19T12:47:20Z</dc:date>
    <item>
      <title>Create Marco variable when it's Monday skip back 3 day else skip 1 day.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76105#M16428</link>
      <description>I am not sure what is not working with the following code.  I am trying to write a macro variable (yesterday) that jumps back to Friday (3 days) when it is Monday, otherwise the Macro variable should jump back one day. Take a look -- &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%LET today=%SYSFUNC(DATE());&lt;BR /&gt;
%LET DAY=%SYSFUNC(PUTN(&amp;amp;today,WEEKDAY.));&lt;BR /&gt;
&lt;BR /&gt;
%MACRO Yester;&lt;BR /&gt;
DATA _NULL_; &lt;BR /&gt;
 %IF %EVAL(&amp;amp;day=2)&lt;BR /&gt;
       %THEN %LET yesterday=%EVAL ((&amp;amp;today*1)-3);&lt;BR /&gt;
       %ELSE %LET yesterday=%EVAL ((&amp;amp;today*1)-1);&lt;BR /&gt;
 run;&lt;BR /&gt;
%MEND Yester;&lt;BR /&gt;
&lt;BR /&gt;
%Yester;&lt;BR /&gt;
&lt;BR /&gt;
%PUT Today:  &amp;amp;today Yesterday:  &amp;amp;yesterday  Day: &amp;amp;Day;

The %IF %EVAL(&amp;amp;day-2) is the way the program was written, just a bad typo in the discussion forum posting.&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: dml</description>
      <pubDate>Sun, 18 Oct 2009 23:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76105#M16428</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-18T23:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create Marco variable when it's Monday skip back 3 day else skip 1 day.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76106#M16429</link>
      <description>The DATA step has no purpose for your code excerpt, and can be eliminated.&lt;BR /&gt;
&lt;BR /&gt;
Also, this type of use of SAS macro variables involves variable "scope", that being either local or global.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
SAS 9.2 Macro Language: Reference - Scopes of Macro Variables&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047080.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047080.htm&lt;/A&gt;</description>
      <pubDate>Mon, 19 Oct 2009 02:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76106#M16429</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-10-19T02:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create Marco variable when it's Monday skip back 3 day else skip 1 day.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76107#M16430</link>
      <description>Hi:&lt;BR /&gt;
  The other issue I see with your code (beyond what Scott has noted with scope issues and the fact that you don't need a DATA _NULL_ step at all), is that &amp;amp;TODAY will hold today's date, but &amp;amp;DAY will hold the result of using the WEEKDAY format.&lt;BR /&gt;
 &lt;BR /&gt;
  You can test the values of these 2 macro variables by doing this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%LET today=%SYSFUNC(DATE());&lt;BR /&gt;
%LET DAY=%SYSFUNC(PUTN(&amp;amp;today,WEEKDAY.));&lt;BR /&gt;
                   &lt;BR /&gt;
%put today= &amp;amp;today;&lt;BR /&gt;
%put day= &amp;amp;day;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
  It seems to me that if you test &amp;amp;TODAY, you will be testing a date value and NOT the day of the week. So, scope issues aside, you might want to consider testing &amp;amp;DAY and not &amp;amp;TODAY. You can take care of some of the scope issues by using an explicit %GLOBAL statement.&lt;BR /&gt;
 &lt;BR /&gt;
  Since the %IF must be used in a Macro program, you will still need the macro program definition for %YESTER. However you do NOT need the DATA _NULL_ and you must still resolve the scope issues if you plan/hope to use &amp;amp;YESTERDAY outside the scope of the local macro program environment.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 19 Oct 2009 02:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76107#M16430</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-10-19T02:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create Marco variable when it's Monday skip back 3 day else skip 1 day.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76108#M16431</link>
      <description>Thanks for the info.  Sorry I had a typo in the posting.  The actual code referenced &amp;amp;day in the %IF condition.  &lt;BR /&gt;
&lt;BR /&gt;
It is a scope problem.  I need/want to make &amp;amp;yesterday global.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again.</description>
      <pubDate>Mon, 19 Oct 2009 11:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76108#M16431</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-19T11:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create Marco variable when it's Monday skip back 3 day else skip 1 day.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76109#M16432</link>
      <description>Thanks, I read the section you pointed to and was able to create a global variable yesterday.  Thanks again!</description>
      <pubDate>Mon, 19 Oct 2009 12:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Marco-variable-when-it-s-Monday-skip-back-3-day-else-skip/m-p/76109#M16432</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-19T12:47:20Z</dc:date>
    </item>
  </channel>
</rss>

