<?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 Create Dynamic Quarterly Report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752404#M237002</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end of each quarter I want to run my SAS program to create a report of all the sales from the prior quarter. In my dataset ("mydata") I have a timestamp for when the sale occurred ("Sale_Timestamp"), formatted as DATETIME20. If I ran this program today (July 6, 2021), I'd want to get a report for all sales that occurred in Q2 (April 1, 2021 - Jun 30, 2021). I can create the macro variables alright, but when I try to add it to my 'where' statement I get a syntax error (but really I think the error has to do with the format of the macro variables). Can anyone see an error in my code below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*prior quarter;
%let qt=%sysfunc(intnx(qtr,%sysfunc(today()),-1),qtr.);

*first day of prior quarter;
%let start_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,b),date9.);

*last day of prior quarter;
%let end_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,e),date9.);

*Test macro variables;
%put &amp;amp;=qt;*2;
%put &amp;amp;=start_dt;*01APR2021;
%put &amp;amp;=end_dt;*30JUN2021;

data test_Q&amp;amp;qt;
set mydata;
where &amp;amp;start_dt &amp;lt;= datepart(Sale_Timestamp) &amp;lt;= &amp;amp;end_dt;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jul 2021 20:18:07 GMT</pubDate>
    <dc:creator>acrosb</dc:creator>
    <dc:date>2021-07-06T20:18:07Z</dc:date>
    <item>
      <title>Create Dynamic Quarterly Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752404#M237002</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end of each quarter I want to run my SAS program to create a report of all the sales from the prior quarter. In my dataset ("mydata") I have a timestamp for when the sale occurred ("Sale_Timestamp"), formatted as DATETIME20. If I ran this program today (July 6, 2021), I'd want to get a report for all sales that occurred in Q2 (April 1, 2021 - Jun 30, 2021). I can create the macro variables alright, but when I try to add it to my 'where' statement I get a syntax error (but really I think the error has to do with the format of the macro variables). Can anyone see an error in my code below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*prior quarter;
%let qt=%sysfunc(intnx(qtr,%sysfunc(today()),-1),qtr.);

*first day of prior quarter;
%let start_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,b),date9.);

*last day of prior quarter;
%let end_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,e),date9.);

*Test macro variables;
%put &amp;amp;=qt;*2;
%put &amp;amp;=start_dt;*01APR2021;
%put &amp;amp;=end_dt;*30JUN2021;

data test_Q&amp;amp;qt;
set mydata;
where &amp;amp;start_dt &amp;lt;= datepart(Sale_Timestamp) &amp;lt;= &amp;amp;end_dt;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 20:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752404#M237002</guid>
      <dc:creator>acrosb</dc:creator>
      <dc:date>2021-07-06T20:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dynamic Quarterly Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752406#M237004</link>
      <description>&lt;PRE&gt;where 01APR2021 &amp;lt;= datepart(Sale_Timestamp) &amp;lt;= 30JUN2021;&lt;/PRE&gt;
&lt;P&gt;That's what your code resolves to and you're correct it's not valid SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either change your code to have the quotes and d:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where "&amp;amp;start_dt"d &amp;lt;= datepart(Sale_Timestamp) &amp;lt;= "&amp;amp;end_dt"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OR you can remove the format from the macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*first day of prior quarter;
%let start_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,b));

*last day of prior quarter;
%let end_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,e));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/104334"&gt;@acrosb&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the end of each quarter I want to run my SAS program to create a report of all the sales from the prior quarter. In my dataset ("mydata") I have a timestamp for when the sale occurred ("Sale_Timestamp"), formatted as DATETIME20. If I ran this program today (July 6, 2021), I'd want to get a report for all sales that occurred in Q2 (April 1, 2021 - Jun 30, 2021). I can create the macro variables alright, but when I try to add it to my 'where' statement I get a syntax error (but really I think the error has to do with the format of the macro variables). Can anyone see an error in my code below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;*prior quarter;
%let qt=%sysfunc(intnx(qtr,%sysfunc(today()),-1),qtr.);

*first day of prior quarter;
%let start_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,b),date9.);

*last day of prior quarter;
%let end_dt=%sysfunc(intnx(qtr,%sysfunc(today()),-1,e),date9.);

*Test macro variables;
%put &amp;amp;=qt;*2;
%put &amp;amp;=start_dt;*01APR2021;
%put &amp;amp;=end_dt;*30JUN2021;

data test_Q&amp;amp;qt;
set mydata;
where &amp;amp;start_dt &amp;lt;= datepart(Sale_Timestamp) &amp;lt;= &amp;amp;end_dt;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 20:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752406#M237004</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-07-06T20:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dynamic Quarterly Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752430#M237021</link>
      <description>&lt;P&gt;Create two macro variables that look like:&lt;/P&gt;
&lt;P&gt;CURR_QTR_DATE_TIME:01JUL21:00:00:00&lt;BR /&gt;and&lt;BR /&gt;LAST_QTR_DATE_TIME=01APR21:00:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;via these statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let last_qtr_date_time=%sysfunc(dhms(%sysfunc(intnx(qtr,%sysfunc(today()),-1,beg)),0,0,0),datetime18.)  ;
%let curr_qtr_date_time=%sysfunc(dhms(%sysfunc(intnx(qtr,%sysfunc(today()),00,beg)),0,0,0),datetime18.)  ;
%put _user_;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then filter based on&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;"&amp;amp;last_qtr_date_time"dt &amp;lt;= my_date_time &amp;lt; "&amp;amp;curr_qtr_date_time"dt ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited note:&amp;nbsp; Oops!&amp;nbsp; You're using dates, not datetimes.&amp;nbsp; Then use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let last_qtr_date=%sysfunc(intnx(qtr,%sysfunc(today()),-1,beg),date9.);
%let curr_qtr_date=%sysfunc(intnx(qtr,%sysfunc(today()),00,beg),date9.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the filter&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  "&amp;amp;last_qtr_date"d &amp;lt;= my_date &amp;lt; "&amp;amp;curr_qtr_date"d;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jul 2021 21:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752430#M237021</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-07-06T21:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dynamic Quarterly Report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752578#M237092</link>
      <description>&lt;P&gt;Ah! Thank you!!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 14:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dynamic-Quarterly-Report/m-p/752578#M237092</guid>
      <dc:creator>acrosb</dc:creator>
      <dc:date>2021-07-07T14:04:18Z</dc:date>
    </item>
  </channel>
</rss>

