<?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 Applying a date condition to my date conditions in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494589#M31865</link>
    <description>&lt;P&gt;I have a SAS EG 7.15 project with a PROC SQL statement that pulls data from a table based on a hard-coded date range condition:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rundate between '01Aug2018:0:0:0'dt and '15Aug2018:0:0:0'dt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This project gets run on the first &amp;amp; third Wednesdays of each month. On the first Wednesday of the month, the date range is changed to pull data from the 16th through the end of the previous month. On the third Wednesday of the month, the date range is again changed to pull data from the 1st - 15th of the current month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to be able to automate this process. However, I'm unsure how I can apply a condition to my condition; for example, how to tell SAS that if it's the first Wednesday of October, the above line needs to read:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rundate between '16Sep2018:0:0:0'dt and '30Sep2018:0:0:0'dt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then, on the third Wednesday of October, it would read:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rundate between '01Oct2018:0:0:0'dt and '15Oct2018:0:0:0'dt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've explored using the NWKDOM() function to no avail; it seems like this situation might be calling for a %macro, with which I have no experience.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help that anyone can provide will certainly be much appreciated!&lt;/P&gt;</description>
    <pubDate>Tue, 11 Sep 2018 18:10:23 GMT</pubDate>
    <dc:creator>mtgkooks</dc:creator>
    <dc:date>2018-09-11T18:10:23Z</dc:date>
    <item>
      <title>Applying a date condition to my date conditions</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494589#M31865</link>
      <description>&lt;P&gt;I have a SAS EG 7.15 project with a PROC SQL statement that pulls data from a table based on a hard-coded date range condition:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rundate between '01Aug2018:0:0:0'dt and '15Aug2018:0:0:0'dt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This project gets run on the first &amp;amp; third Wednesdays of each month. On the first Wednesday of the month, the date range is changed to pull data from the 16th through the end of the previous month. On the third Wednesday of the month, the date range is again changed to pull data from the 1st - 15th of the current month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to be able to automate this process. However, I'm unsure how I can apply a condition to my condition; for example, how to tell SAS that if it's the first Wednesday of October, the above line needs to read:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rundate between '16Sep2018:0:0:0'dt and '30Sep2018:0:0:0'dt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then, on the third Wednesday of October, it would read:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rundate between '01Oct2018:0:0:0'dt and '15Oct2018:0:0:0'dt&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I've explored using the NWKDOM() function to no avail; it seems like this situation might be calling for a %macro, with which I have no experience.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help that anyone can provide will certainly be much appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 18:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494589#M31865</guid>
      <dc:creator>mtgkooks</dc:creator>
      <dc:date>2018-09-11T18:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Applying a date condition to my date conditions</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494593#M31866</link>
      <description>You likely want INTNX + NWKDOM.</description>
      <pubDate>Tue, 11 Sep 2018 18:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494593#M31866</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-11T18:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Applying a date condition to my date conditions</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494605#M31867</link>
      <description>&lt;P&gt;First, I'm assuming that you have a query that includes the between filter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 1, create a code node in your project, and add this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Temp1;
	format ThisDate datetime.;
	format StartDate datetime.;
	format EndDate datetime.;
	ThisDate = datetime();
	ThisDay = day(datepart(ThisDate));

	if ThisDay &amp;lt;=14
		then do; /* Must be first Wednesday of month */
		EndDate = intnx("dtmonth", ThisDate, -1, "end");
		StartDate = dhms(mdy(month(datepart(EndDate)), 16, year(datepart(EndDate))), 0, 0, 0);
	end;
	else do;
		StartDate = dhms(mdy(month(datepart(ThisDate)), 1, year(datepart(ThisDate))), 0, 0, 0);
		EndDate = dhms(mdy(month(datepart(ThisDate)), 15, year(datepart(ThisDate))), 23, 59, 59);
	end;

	output;
	call symput("StartDate", put(StartDate, datetime.));
	call symput("EndDate", put(EndDate, datetime.));
run;

%put &amp;amp;=StartDate.;
%put &amp;amp;=EndDate.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run it, and play with it, and see if the results are what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 2, modify your query, changing the hardcoded dates to look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&amp;amp;StartDate."dt&lt;BR /&gt;"&amp;amp;EndDate."dt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the whole thing, and make sure it does what you want. Once it does, you can greatly shorten the code node to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	ThisDate = datetime(); ThisDate = "27sep2018:00:00:00"dt;
	ThisDay = day(datepart(ThisDate));

	if ThisDay &amp;lt;=14 then do;

		/* Must be first Wednesday of month */
		EndDate = intnx("dtmonth", ThisDate, -1, "end");
		StartDate = dhms(mdy(month(datepart(EndDate)), 16, year(datepart(EndDate))), 0, 0, 0);
	end;
	else do;
		StartDate = dhms(mdy(month(datepart(ThisDate)), 1, year(datepart(ThisDate))), 0, 0, 0);
		EndDate = dhms(mdy(month(datepart(ThisDate)), 15, year(datepart(ThisDate))), 23, 59, 59);
	end;

	call symput("StartDate", put(StartDate, datetime.));
	call symput("EndDate", put(EndDate, datetime.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and you should be good to go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 18:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494605#M31867</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-09-11T18:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Applying a date condition to my date conditions</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494610#M31868</link>
      <description>Thanks a lot, Tom!&lt;BR /&gt;I will give this a try and let you know how it turns out.</description>
      <pubDate>Tue, 11 Sep 2018 19:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494610#M31868</guid>
      <dc:creator>mtgkooks</dc:creator>
      <dc:date>2018-09-11T19:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Applying a date condition to my date conditions</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494895#M31892</link>
      <description>&lt;P&gt;Here is one more idea... you can use a macro to conditionally run your PROC SQL code based on whether the current date is either the 1st Wednesday or the 3rd Wednesday of each month. Something similar to the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro abc;&lt;/P&gt;
&lt;P&gt;%let td=%sysfunc(today()); /* today's date */&lt;BR /&gt;%let first=%sysfunc(nwkdom(1,4,%sysfunc(month(&amp;amp;td)),%sysfunc(year(&amp;amp;td)))); /* first wednesday of month */&lt;BR /&gt;%let third=%sysfunc(nwkdom(3,4,%sysfunc(month(&amp;amp;td)),%sysfunc(year(&amp;amp;td)))); /* third wednesday of month */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;td=&amp;amp;first %then %do;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; proc sql;&lt;BR /&gt; create table want as select * from have&lt;BR /&gt; where date between '16AUG2018:0:0:0'dt and '30AUG2018:0:0:0'dt;&lt;BR /&gt; quit;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%else %if &amp;amp;td=&amp;amp;third %then %do;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; proc sql;&lt;BR /&gt; create table want as select * from have&lt;BR /&gt; where date between '1SEP2018:0:0:0'dt and '16SEP2018:0:0:0'dt;&lt;BR /&gt; quit;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%abc&lt;/P&gt;</description>
      <pubDate>Wed, 12 Sep 2018 15:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Applying-a-date-condition-to-my-date-conditions/m-p/494895#M31892</guid>
      <dc:creator>jebjur</dc:creator>
      <dc:date>2018-09-12T15:26:02Z</dc:date>
    </item>
  </channel>
</rss>

