<?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: logic to find data on particular number of days in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937825#M368465</link>
    <description>&lt;P&gt;As I understand the question, you want the &lt;STRONG&gt;End_Date&lt;/STRONG&gt;&amp;nbsp;to be one&amp;nbsp;&lt;EM&gt;working day&lt;/EM&gt; before today and&amp;nbsp;&lt;STRONG&gt;Start_Date&lt;/STRONG&gt;&amp;nbsp;to be two&amp;nbsp;&lt;EM&gt;working days&lt;/EM&gt; before the &lt;STRONG&gt;End_Date&lt;/STRONG&gt;, resulting in a 3-day timespan. If so, how about this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo_dates;
	length Today Start_Date End_Date Weekday 8;
	do Today='29JUL2024'd to '05AUG2024'd;
  		Weekday  = weekday(today);
		end_date   = intnx('weekday', today, -1);
		start_date = intnx('weekday', end_date, -2);
		if 2&amp;lt;=Weekday &amp;lt;=6 then output;
	end;
  format today start_date end_date weekdate.;
run;

proc print data=demo_dates;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Results:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.DEMO_DATES" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Today&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Start_Date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;End_Date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Weekday&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;Monday, July 29, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Wednesday, July 24, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Friday, July 26, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;Tuesday, July 30, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Thursday, July 25, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Monday, July 29, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;Wednesday, July 31, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Friday, July 26, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Tuesday, July 30, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;Thursday, August 1, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Monday, July 29, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Wednesday, July 31, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;Friday, August 2, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Tuesday, July 30, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Thursday, August 1, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="r data"&gt;Monday, August 5, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Wednesday, July 31, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Friday, August 2, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 31 Jul 2024 20:47:26 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2024-07-31T20:47:26Z</dc:date>
    <item>
      <title>logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937813#M368464</link>
      <description>&lt;P&gt;Hi, I have a date dataset that assigns start date and end date based on the weekday, excluding weekend. Using&amp;nbsp; the date function I want to calculate the data on 3 days of the date window. Right now the code doesn't evaluate if the data is present on all 3 days, it just pulls whatever data is available even if its on the start date or on the end date or on both. Should introducing middle day solve the issue ? Any insights would be helpful!&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data myora.temp_dates;
  wd = weekday(today());
  if wd = 2 then end_date = today() - 3;
  else end_date = today() - 1;
  
  if wd in (2,3,4) then start_date = today() - 5;
  else start_date = today() - 3;
  
  format start_date end_date date9.;
run;

select 
       	id,
		num, 
		name,
		COUNT(*) AS name_count, 
		t.start_date,
		t.end_date,    
       
from initial_data1
cross join temp_dates t
where auth_dt &amp;gt;= t.start_date 
	and auth_dt &amp;lt;= t.end_date
	and TO_CHAR(auth_dt, 'Dy') NOT IN ('Sat', 'Sun')
group by id,num,name,t.start_date, t.end_date
having count(*) &amp;gt;= 10 and sum(amt) &amp;gt;= 100&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 19:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937813#M368464</guid>
      <dc:creator>User_2024</dc:creator>
      <dc:date>2024-07-31T19:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937825#M368465</link>
      <description>&lt;P&gt;As I understand the question, you want the &lt;STRONG&gt;End_Date&lt;/STRONG&gt;&amp;nbsp;to be one&amp;nbsp;&lt;EM&gt;working day&lt;/EM&gt; before today and&amp;nbsp;&lt;STRONG&gt;Start_Date&lt;/STRONG&gt;&amp;nbsp;to be two&amp;nbsp;&lt;EM&gt;working days&lt;/EM&gt; before the &lt;STRONG&gt;End_Date&lt;/STRONG&gt;, resulting in a 3-day timespan. If so, how about this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo_dates;
	length Today Start_Date End_Date Weekday 8;
	do Today='29JUL2024'd to '05AUG2024'd;
  		Weekday  = weekday(today);
		end_date   = intnx('weekday', today, -1);
		start_date = intnx('weekday', end_date, -2);
		if 2&amp;lt;=Weekday &amp;lt;=6 then output;
	end;
  format today start_date end_date weekdate.;
run;

proc print data=demo_dates;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Results:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.DEMO_DATES" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Today&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Start_Date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;End_Date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Weekday&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data"&gt;Monday, July 29, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Wednesday, July 24, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Friday, July 26, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;Tuesday, July 30, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Thursday, July 25, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Monday, July 29, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;Wednesday, July 31, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Friday, July 26, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Tuesday, July 30, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;Thursday, August 1, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Monday, July 29, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Wednesday, July 31, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;Friday, August 2, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Tuesday, July 30, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Thursday, August 1, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="r data"&gt;Monday, August 5, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Wednesday, July 31, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;Friday, August 2, 2024&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 31 Jul 2024 20:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937825#M368465</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2024-07-31T20:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937830#M368466</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464126"&gt;@User_2024&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, I have a date dataset that assigns start date and end date based on the weekday, excluding weekend. Using&amp;nbsp; the date function I want to calculate the data on 3 days of the date window. Right now the code doesn't evaluate if the data is present on all 3 days, it just pulls whatever data is available even if its on the start date or on the end date or on both.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am not sure that I understand what you want. Can you show a couple of different worked examples given a specific date as the basis and the actual dates of data that you want?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One interpretation of what I &lt;STRONG&gt;imagine&lt;/STRONG&gt; you may want would be this that excludes the boundary dates.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;where auth_dt &amp;gt; t.start_date 
	and auth_dt &amp;lt; t.end_date&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are requiring data to be present on all three days that may be a bit more complicated.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 21:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937830#M368466</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-31T21:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937846#M368469</link>
      <description>&lt;P&gt;Yes., your logic for the weekday is correct, There is no issue in the date function, the problem is I want to pull the accts if they have data on ALL 3 days not just on 1 day or 2 days.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I made an example data table, my logic is pulling both Yes and NO records. I want the code to pull only the YES (where data presents in ALL three days, not just across one or two days) . Thanks again for the help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="399"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="54"&gt;Acct nm&lt;/TD&gt;
&lt;TD width="92"&gt;Data present in 1st date&lt;/TD&gt;
&lt;TD width="92"&gt;Data present in 2nd day&lt;/TD&gt;
&lt;TD width="85"&gt;Data present in 3rd day&lt;/TD&gt;
&lt;TD width="76"&gt;Query should pull ?&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="54"&gt;1234&lt;/TD&gt;
&lt;TD width="92"&gt;aa&lt;/TD&gt;
&lt;TD width="92"&gt;ab&lt;/TD&gt;
&lt;TD width="85"&gt;abc&lt;/TD&gt;
&lt;TD width="76"&gt;Yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="54"&gt;4567&lt;/TD&gt;
&lt;TD width="92"&gt;aa&lt;/TD&gt;
&lt;TD width="92"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="85"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="76"&gt;No&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="54"&gt;7890&lt;/TD&gt;
&lt;TD width="92"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="92"&gt;bc&lt;/TD&gt;
&lt;TD width="85"&gt;bb&lt;/TD&gt;
&lt;TD width="76"&gt;No&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="54"&gt;1357&lt;/TD&gt;
&lt;TD width="92"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="92"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="85"&gt;bb&lt;/TD&gt;
&lt;TD width="76"&gt;No&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="54"&gt;4802&lt;/TD&gt;
&lt;TD width="92"&gt;aa&lt;/TD&gt;
&lt;TD width="92"&gt;aa&lt;/TD&gt;
&lt;TD width="85"&gt;aa&lt;/TD&gt;
&lt;TD width="76"&gt;yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 01 Aug 2024 00:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937846#M368469</guid>
      <dc:creator>User_2024</dc:creator>
      <dc:date>2024-08-01T00:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937847#M368470</link>
      <description>&lt;P&gt;In your HAVING CLAUSE&amp;nbsp; add&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  AND COUNT(DISTINCT DATE)=3&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2024 01:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937847#M368470</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-08-01T01:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937855#M368471</link>
      <description>&lt;P&gt;this helped thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 02:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937855#M368471</guid>
      <dc:creator>User_2024</dc:creator>
      <dc:date>2024-08-01T02:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937872#M368474</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464126"&gt;@User_2024&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464126"&gt;@User_2024&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;this helped thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In this case it would be fair and help later readers if you marked the helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select the appropriate post&amp;nbsp;as the solution after clicking&amp;nbsp;"Not the Solution" in the option menu (see icon below) of the current solution.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="show_option_menu.png" style="width: 155px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98907i215414026C0E61F8/image-size/large?v=v2&amp;amp;px=999" role="button" title="show_option_menu.png" alt="show_option_menu.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 06:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937872#M368474</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-08-01T06:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: logic to find data on particular number of days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937921#M368481</link>
      <description>Thanks for indicating me, I am relatively new to the page and wasn't aware of the changing option. I was actually meaning to CHOOSE the solution as solution and not my own post.  I corrected it now. Hope it helps.</description>
      <pubDate>Thu, 01 Aug 2024 12:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/logic-to-find-data-on-particular-number-of-days/m-p/937921#M368481</guid>
      <dc:creator>User_2024</dc:creator>
      <dc:date>2024-08-01T12:30:22Z</dc:date>
    </item>
  </channel>
</rss>

