<?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: How do I create if condition with date macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610125#M177665</link>
    <description>Just play with it. Save the results of the INTNX() function calls into variables and print them.&lt;BR /&gt;Why not just use MONTH(TODAY()) and check whether it is 1 (January), 4 (April), 7 (July) or 10 (October)?&lt;BR /&gt;</description>
    <pubDate>Fri, 06 Dec 2019 21:17:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-12-06T21:17:05Z</dc:date>
    <item>
      <title>How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609965#M177605</link>
      <description>&lt;P&gt;Hello all, I'm hoping someone can help, as I am fairly new with SAS. I couldn't find anywhere on the forum that specifically addressed what I am trying to do. I am trying to make the code run only if my date criteria is met.&lt;BR /&gt;&lt;BR /&gt;I want to run (automate) the previous quarter of data, but only if it is &amp;gt;2 months after the end of the previous quarter, for example, I want to run data for 01JUL2019 - 30SEP2019, but run it no earlier than 01DEC2019 to make sure all the data is caught up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symput('startdt',"'"||put(intnx('quarter', today(),-1, 'B'), date9.)||"'D");
call symput('ENDdt',"'"||put(intnx('quarter', today(), -1, 'E'), date9.)||"'D");
run;
%put &amp;amp;startdt.;
%put &amp;amp;ENDdt.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So for this to run, date of intnx('quarter', today(),-1, 'B') should be equal to intnx('month', today(),-5, 'B')&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 14:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609965#M177605</guid>
      <dc:creator>vanpeltm1785</dc:creator>
      <dc:date>2019-12-06T14:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609967#M177607</link>
      <description>&lt;P&gt;Sounds like you want to test if there are two months between ENDDT and TODAY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if intck('month',"&amp;amp;enddt"d,today()) &amp;gt;= 2 then ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 14:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609967#M177607</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-06T14:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609970#M177609</link>
      <description>&lt;P&gt;Have the scheduler run your program on first of March, June, September and December.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 14:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609970#M177609</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-06T14:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609972#M177611</link>
      <description>&lt;P&gt;Hmm, that looks like it could work, but where in the code would I put that? because enddt will not yet be defined if the "if" statement with that comes first, correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 14:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609972#M177611</guid>
      <dc:creator>vanpeltm1785</dc:creator>
      <dc:date>2019-12-06T14:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609974#M177613</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/161731"&gt;@vanpeltm1785&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hmm, that looks like it could work, but where in the code would I put that? because enddt will not yet be defined if the "if" statement with that comes first, correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes for that test to work you need to first do that calculation that gave you the end date you want to test.&lt;/P&gt;
&lt;P&gt;You need to explain more about what you want to happen to get more precise advice.&amp;nbsp; What do you want to do when it is time to run? What do you want to do when it is NOT time to run?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 14:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/609974#M177613</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-06T14:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610061#M177629</link>
      <description>If the date criteria is met, I would like the date outputs to be assigned, if the criteria is not met, just an error that wont assign the dates, or even a message that says the criteria was not met</description>
      <pubDate>Fri, 06 Dec 2019 18:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610061#M177629</guid>
      <dc:creator>vanpeltm1785</dc:creator>
      <dc:date>2019-12-06T18:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610093#M177639</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/161731"&gt;@vanpeltm1785&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;If the date criteria is met, I would like the date outputs to be assigned, if the criteria is not met, just an error that wont assign the dates, or even a message that says the criteria was not met&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startdt=NONE;
%let enddt=NONE;
data _null_;
  now=today();
  start = intnx('quarter',now,-1,'b');
  end = intnx('quarter',now,-1,'e');
  if intnx('month',end,now) &amp;gt;= 2 then do;
    call symput('startdt',"'"||put(start, date9.)||"'D");
    call symput('ENDdt',"'"||put(end, date9.)||"'D");
  end;
  else put 'NOTE:  Will not run on ' now date9. ' since not 2 or more months after ' end date9. '.';
run;
%put &amp;amp;startdt.;
%put &amp;amp;ENDdt.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 20:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610093#M177639</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-06T20:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610117#M177658</link>
      <description>&lt;P&gt;I'm not sure what, but something here is not working, it could be this: "if intnx('month',end,now) &amp;gt;=2 then do;"&lt;/P&gt;&lt;P&gt;what would that resolve to numerically or date-wise?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also, I want the code to error if it is &amp;gt;=2, and only run if =3 months after, is this still the right way to put the if else?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lastly, the else statement does not resolve and output the error message&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 20:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610117#M177658</guid>
      <dc:creator>vanpeltm1785</dc:creator>
      <dc:date>2019-12-06T20:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610118#M177659</link>
      <description>&lt;P&gt;Thanks, I am hoping to figure out how to code it myself to better understand it, but this might be the eventual solution!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 20:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610118#M177659</guid>
      <dc:creator>vanpeltm1785</dc:creator>
      <dc:date>2019-12-06T20:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610125#M177665</link>
      <description>Just play with it. Save the results of the INTNX() function calls into variables and print them.&lt;BR /&gt;Why not just use MONTH(TODAY()) and check whether it is 1 (January), 4 (April), 7 (July) or 10 (October)?&lt;BR /&gt;</description>
      <pubDate>Fri, 06 Dec 2019 21:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610125#M177665</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-06T21:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create if condition with date macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610132#M177669</link>
      <description>&lt;P&gt;Thanks, I moved a round a few things, but primarily changed "if &lt;STRONG&gt;intnx&lt;/STRONG&gt;('month',end,now) &lt;STRONG&gt;&amp;gt;=2&lt;/STRONG&gt; then do;" to "if &lt;STRONG&gt;intck&lt;/STRONG&gt;('month',end,now) &lt;STRONG&gt;= 3&lt;/STRONG&gt; then do;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that seem right? seems to be giving me the output I want... Here is my full adjustment:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startdt=NOTE: WILL NOT RUN BECAUSE THE REPORT MUST BE RUN IN THE THIRD MONTH AFTER THE PREVIOUS QUARTER ENDED,EXAMPLE-IF THE QUARTER ENDS SEPT 30, YOU MUST WAIT UNTIL AT LEAST DEC 01 TO RUN;
%let enddt=NOTE: WILL NOT RUN BECAUSE THE REPORT MUST BE RUN IN THE THIRD MONTH AFTER THE PREVIOUS QUARTER ENDED,EXAMPLE-IF THE QUARTER ENDS SEPT 30, YOU MUST WAIT UNTIL AT LEAST DEC 01 TO RUN;
data _null_;
  now=today();
  start = intnx('quarter',now,-1,'b');
  end = intnx('quarter',now,-1,'e');
  if intck('month',end,now) = 3 then do;
    call symput('startdt',"'"||put(start, date9.)||"'D");
    call symput('ENDdt',"'"||put(end, date9.)||"'D");
	call symput('MonthCount',"(((("||put(intck('month',end,now),10.)||" Months       ))))");
end;
else call symput('MonthCount',"(((("||put(intck('month',end,now),10.)||" Months       ))))");
run;
%put &amp;amp;startdt.;
%put &amp;amp;ENDdt.;
%put &amp;amp;MonthCount.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 21:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-if-condition-with-date-macro/m-p/610132#M177669</guid>
      <dc:creator>vanpeltm1785</dc:creator>
      <dc:date>2019-12-06T21:39:48Z</dc:date>
    </item>
  </channel>
</rss>

