<?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 how to calcuate date for weekdays using toda() in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/738743#M230485</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a record tracking patient&amp;nbsp;data that is collected on a daily basis, Monday through Friday. The tracking data collects number of new patients on a daily basis. I have a date column along with number of patients. What I want to do is if the date column&amp;nbsp;is todays date (so (today()) then sum the patient numbers by clients and mark them as new patients (new_pts). I want to run this every morning but grabbing the data from the night before (I have this running on a task scheduler), the issue is two fold , (1) how do I run this so it that the date column is today() -1&amp;nbsp; and (2) when I am running the data on Monday morning I need it to identify the new patients from Friday so today()-1 wont work. In the below example lets pretend that today is May 3 2021.&lt;/P&gt;&lt;P&gt;I have below a sample code of what I have already, but how to accomplish the two issues above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat client 2. date mmddyy10. no_pts 1.;
input client date no_pts;
format date mmddyy10.;
datalines;
1	04122021 1
2	04132021 1
3	04142021 2
4	04152021 2
5	04162021 0
6	04172021 1
7	04182021 1
8	04192021 1
9	05032021 1
9	05032021 1
11	05032021 1
;
run;

proc sql;
create table want as
select distinct client, 
case when date=today() then sum(no_pts) else 0 end as new_pts,
sum(no_pts) as all_pts
from have
group by client;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 May 2021 23:26:49 GMT</pubDate>
    <dc:creator>sas_student1</dc:creator>
    <dc:date>2021-05-03T23:26:49Z</dc:date>
    <item>
      <title>how to calcuate date for weekdays using toda()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/738743#M230485</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a record tracking patient&amp;nbsp;data that is collected on a daily basis, Monday through Friday. The tracking data collects number of new patients on a daily basis. I have a date column along with number of patients. What I want to do is if the date column&amp;nbsp;is todays date (so (today()) then sum the patient numbers by clients and mark them as new patients (new_pts). I want to run this every morning but grabbing the data from the night before (I have this running on a task scheduler), the issue is two fold , (1) how do I run this so it that the date column is today() -1&amp;nbsp; and (2) when I am running the data on Monday morning I need it to identify the new patients from Friday so today()-1 wont work. In the below example lets pretend that today is May 3 2021.&lt;/P&gt;&lt;P&gt;I have below a sample code of what I have already, but how to accomplish the two issues above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat client 2. date mmddyy10. no_pts 1.;
input client date no_pts;
format date mmddyy10.;
datalines;
1	04122021 1
2	04132021 1
3	04142021 2
4	04152021 2
5	04162021 0
6	04172021 1
7	04182021 1
8	04192021 1
9	05032021 1
9	05032021 1
11	05032021 1
;
run;

proc sql;
create table want as
select distinct client, 
case when date=today() then sum(no_pts) else 0 end as new_pts,
sum(no_pts) as all_pts
from have
group by client;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 23:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/738743#M230485</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2021-05-03T23:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to calcuate date for weekdays using toda()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/738764#M230492</link>
      <description>&lt;P&gt;Instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;today()-1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('weekday',today(),-1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will generate the same value as today()-1 for Tuesdays, Wednesdays, Thursdays, and Fridays.&amp;nbsp; But for Mondays it will generate the date of the prior Friday.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 02:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/738764#M230492</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-04T02:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to calcuate date for weekdays using toda()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/739348#M230740</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; Ah! thanks! simple solution!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another issue that I hope you are able to assist in this thread. It is kind of related.&lt;/P&gt;&lt;P&gt;In the same data run I am creating a proc report that I ODS export, I have a title that currently reads as follows:&lt;/P&gt;&lt;P&gt;title2 j=l h=11pt color=black font='Calibri'&lt;BR /&gt;"^{style[fontweight=bold color=black] Date Complete: %sysfunc(date(),mmddyy10.)}";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above takes todays date and populates as date complete. How would I change the above so it would take yesterdays date and if yesterday date is a Sunday it would populate Fridays date instead? I thought adding the 'weekday' may work but it didn't.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 21:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/739348#M230740</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2021-05-05T21:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to calcuate date for weekdays using toda()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/739364#M230749</link>
      <description>&lt;P&gt;You can take the original expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; intnx('weekday',today(),-1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and embed each function call in %sysfunc, as in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(intnx(weekday,%sysfunc(date()),-1),mmddyy10.);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 May 2021 22:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/739364#M230749</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-05T22:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to calcuate date for weekdays using toda()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/739366#M230751</link>
      <description>wow! an easy solution! I was trying to add the original function within in the %sysfunc but didn't realize that I need to also change the today() and remove the quotes.&lt;BR /&gt;&lt;BR /&gt;Thank you!!!</description>
      <pubDate>Wed, 05 May 2021 22:25:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calcuate-date-for-weekdays-using-toda/m-p/739366#M230751</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2021-05-05T22:25:22Z</dc:date>
    </item>
  </channel>
</rss>

