<?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: macro function to output yesterday's data and 3 days of data if the weekend in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/239170#M308778</link>
    <description>&lt;P&gt;I am receiving the below warning/error:&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference startdate not resolved.&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant "&amp;amp;startdate"d.&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant "&amp;amp;enddate"d.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my&amp;nbsp;exact&amp;nbsp;code:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro datebound;&lt;BR /&gt;%let today=%sysfunc(today(),date9.);&lt;BR /&gt;%let day=%sysfunc(weekday("&amp;amp;today"d));&lt;/P&gt;&lt;P&gt;%if &amp;amp;day=2 %then %do;&lt;BR /&gt;%let startdate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-3),date9.);&lt;BR /&gt;%let enddate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let startdate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);&lt;BR /&gt;%let enddate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);&lt;BR /&gt;%end;&lt;BR /&gt;%put startdate= &amp;amp;startdate enddate= &amp;amp;enddate;&lt;BR /&gt;%mend;&lt;BR /&gt;%datebound;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE POLICY AS&lt;BR /&gt;SELECT&lt;BR /&gt;A.datebound,&lt;BR /&gt;A.Customer_ID,&lt;BR /&gt;A.InsFirstLast,&lt;BR /&gt;C.FirstName,&lt;BR /&gt;C.LastName,&lt;BR /&gt;A.email,&lt;BR /&gt;A.PlanCode,&lt;BR /&gt;A.Policy,&lt;BR /&gt;DATEPART(A.DateBound) AS FeedbackDate FORMAT MMDDYY10.,&lt;BR /&gt;A.DistributionChannel,&lt;BR /&gt;A.Carrier,&lt;BR /&gt;A.PlanType,&lt;BR /&gt;B.Supervisor,&lt;BR /&gt;B.Name&lt;BR /&gt;FROM&lt;BR /&gt;CorpAn.DirectNBPolicies A&lt;BR /&gt;LEFT JOIN CorpAn.Employee B ON A.I_EmpID = B.I_EmpID&lt;BR /&gt;LEFT JOIN AgCube.tbl_CustomerRelationShip C ON UPPER(A.InsFirstLast) = UPPER(C.FullName)&lt;BR /&gt;WHERE&lt;BR /&gt;"&amp;amp;startdate"d&amp;lt;= datebound &amp;lt;="&amp;amp;enddate"d&lt;BR /&gt;AND A.MediaCode NE '30'&lt;BR /&gt;AND A.email LIKE ('%@%')&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Dec 2015 15:38:15 GMT</pubDate>
    <dc:creator>Roddy</dc:creator>
    <dc:date>2015-12-14T15:38:15Z</dc:date>
    <item>
      <title>macro function to output yesterday's data and 3 days of data if the weekend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238939#M308774</link>
      <description>&lt;P&gt;I am using the following macro variable to give me yesterday's data ... %let startdate = today()-1&lt;/P&gt;&lt;P&gt;How do I set this up so that this works during the week, but when I pull the data on Monday, the results include Friday, Saturday and Sunday?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table order as select&amp;nbsp;id,&amp;nbsp;createdate&lt;/P&gt;&lt;P&gt;from x.table&lt;/P&gt;&lt;P&gt;where createdate = &amp;amp;startdate.&lt;/P&gt;&lt;P&gt;; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 16:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238939#M308774</guid>
      <dc:creator>Roddy</dc:creator>
      <dc:date>2015-12-11T16:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: macro function to output yesterday's data and 3 days of data if the weekend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238955#M308775</link>
      <description>&lt;P&gt;You could define macro variable STARTDATE as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if weekday(today())=2 then call symput('startdate', 'today()-1 | createdate=today()-2 | createdate=today()-3');
else call symput('startdate', 'today()-1');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively, if it was no problem to change your&amp;nbsp;WHERE condition to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where today()-createdate in (&amp;amp;daylist)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you could define DAYLIST like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if weekday(today())=2 then call symput('daylist', '1,2,3');
else call symput('daylist', '1');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: Please note that in both cases the code to create the macro variable would need to run on the same day as the PROC SQL step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 18:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238955#M308775</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-11T18:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: macro function to output yesterday's data and 3 days of data if the weekend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238961#M308776</link>
      <description>&lt;P&gt;I don't think your %let statement is correct, as SAS would read the value of startdate as "today()-1".&amp;nbsp; The below macro will create a startdate and an enddate for the createdate filter.&amp;nbsp; If the current day you run it is Monday, it will set startdate 3 days ago and enddate to yesterday.&amp;nbsp; If the current day you run it is not a Monday, it will set both startdate and enddate to yesterday.&amp;nbsp; I also modify your where statement in the SQL procedure to call the dates with a date literal.&amp;nbsp; Hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro createdate;
%let today=%sysfunc(today(),date9.);
%let day=%sysfunc(weekday("&amp;amp;today"d));

%if &amp;amp;day=2 %then %do;
	%let startdate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-3),date9.);
	%let enddate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);
%end;
%else %do;
	%let startdate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);
	%let enddate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);
%end;
%put startdate= &amp;amp;startdate enddate= &amp;amp;enddate;
%mend;
%createdate;

proc sql;
create table order as
select id, createdate
from x.table
where "&amp;amp;startdate"d&amp;lt;= createdate &amp;lt;="&amp;amp;enddate"d;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 18:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238961#M308776</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-12-11T18:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro function to output yesterday's data and 3 days of data if the weekend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238989#M308777</link>
      <description>&lt;P&gt;The INTNX option also supports the WEEKDAY interval, not just DAY interval.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 20:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/238989#M308777</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-11T20:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro function to output yesterday's data and 3 days of data if the weekend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/239170#M308778</link>
      <description>&lt;P&gt;I am receiving the below warning/error:&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference startdate not resolved.&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant "&amp;amp;startdate"d.&lt;/P&gt;&lt;P&gt;ERROR: Invalid date/time/datetime constant "&amp;amp;enddate"d.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my&amp;nbsp;exact&amp;nbsp;code:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro datebound;&lt;BR /&gt;%let today=%sysfunc(today(),date9.);&lt;BR /&gt;%let day=%sysfunc(weekday("&amp;amp;today"d));&lt;/P&gt;&lt;P&gt;%if &amp;amp;day=2 %then %do;&lt;BR /&gt;%let startdate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-3),date9.);&lt;BR /&gt;%let enddate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let startdate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);&lt;BR /&gt;%let enddate=%sysfunc(intnx(DAY,"&amp;amp;today"d,-1),date9.);&lt;BR /&gt;%end;&lt;BR /&gt;%put startdate= &amp;amp;startdate enddate= &amp;amp;enddate;&lt;BR /&gt;%mend;&lt;BR /&gt;%datebound;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE POLICY AS&lt;BR /&gt;SELECT&lt;BR /&gt;A.datebound,&lt;BR /&gt;A.Customer_ID,&lt;BR /&gt;A.InsFirstLast,&lt;BR /&gt;C.FirstName,&lt;BR /&gt;C.LastName,&lt;BR /&gt;A.email,&lt;BR /&gt;A.PlanCode,&lt;BR /&gt;A.Policy,&lt;BR /&gt;DATEPART(A.DateBound) AS FeedbackDate FORMAT MMDDYY10.,&lt;BR /&gt;A.DistributionChannel,&lt;BR /&gt;A.Carrier,&lt;BR /&gt;A.PlanType,&lt;BR /&gt;B.Supervisor,&lt;BR /&gt;B.Name&lt;BR /&gt;FROM&lt;BR /&gt;CorpAn.DirectNBPolicies A&lt;BR /&gt;LEFT JOIN CorpAn.Employee B ON A.I_EmpID = B.I_EmpID&lt;BR /&gt;LEFT JOIN AgCube.tbl_CustomerRelationShip C ON UPPER(A.InsFirstLast) = UPPER(C.FullName)&lt;BR /&gt;WHERE&lt;BR /&gt;"&amp;amp;startdate"d&amp;lt;= datebound &amp;lt;="&amp;amp;enddate"d&lt;BR /&gt;AND A.MediaCode NE '30'&lt;BR /&gt;AND A.email LIKE ('%@%')&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 15:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/239170#M308778</guid>
      <dc:creator>Roddy</dc:creator>
      <dc:date>2015-12-14T15:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro function to output yesterday's data and 3 days of data if the weekend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/239191#M308779</link>
      <description>&lt;P&gt;To avoid the warning and error messages you should insert a %GLOBAL statement at the beginning of your macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro datebound;
%global startdate enddate;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise, the two macro variables are &lt;EM&gt;local&lt;/EM&gt; to macro datebound and seize to exist once macro execution has finished.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 16:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-to-output-yesterday-s-data-and-3-days-of-data-if/m-p/239191#M308779</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-12-14T16:37:49Z</dc:date>
    </item>
  </channel>
</rss>

