<?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 change a WHERE/ or IF THEN-condition depending on which date it is? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790129#M252935</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Played around a bit with your code and it worked like a charm!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Kurt.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET generic_today=today()+780;
data want;
FORMAT generic_today Cutoff YYMMDD10.;
set have;
generic_today = &amp;amp;generic_today;
if '01jan2022'd le generic_today le '31oct2022'd
then cutoff = '01oct2021'd;
else cutoff = intnx('month',generic_today,-13,'b');
if date ge cutoff;
/*drop cutoff;*/
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 12:55:39 GMT</pubDate>
    <dc:creator>Pili1100</dc:creator>
    <dc:date>2022-01-14T12:55:39Z</dc:date>
    <item>
      <title>How do I change a WHERE/ or IF THEN-condition depending on which date it is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790120#M252933</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.HAVE;
INFILE DATALINES DELIMITER =','; 
FORMAT Date YYMMDD10. ;
INPUT DATE YYMMDD10. X  ;
CARDS; 
2021-08-17,99,
2021-09-01,505,
2021-10-05,91,
2021-11-05,65,
2021-12-07,250,
2022-01-01,704,
2022-02-02,687,
2022-03-03,123,
2022-04-03,456,
2022-05-06,789,
2022-06-16,687,
2022-07-27,123,
2022-08-05,400,
2022-09-05,700,
2022-10-22,850,
2022-11-18,700,
2022-12-07,120,
2023-01-27,123,
2023-02-05,400,
2023-03-07,700,
2023-04-22,850,
2023-05-18,700,
2023-06-07,120,
;
RUN;

DATA have;
SET have;
row= _n_;
RUN;


DATA cond_1;
FORMAT today YYMMDD10.;
SET have;
row= _n_;
/*If today's date is... */
today = '15MAR2022'd;

/*Then these rows are the rows I want  */
IF row &amp;gt;2 AND row &amp;lt; 9 THEN DO;  
condition_1 = 'Yes';
OUTPUT;
END;

RUN;


DATA cond_2;
FORMAT today YYMMDD10.;
SET have;
row= _n_;
/*If today's date is... */
today = '15MAY2023'd;

/*Then these rows are the rows I want  */
IF row &amp;gt;8 AND row &amp;lt; 22 THEN DO;  
condition_2 = 'Yes';
OUTPUT;
END;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How do I change a WHERE/ or IF THEN-condition depending on which date it is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two conditions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Condition 1&lt;/P&gt;
&lt;P&gt;If today's date is between 1&lt;SUP&gt;st&lt;/SUP&gt; of JAN 2022 to 31&lt;SUP&gt;st&lt;/SUP&gt; of OCT 2022 = table contains data from&lt;/P&gt;
&lt;P&gt;1&lt;SUP&gt;st&lt;/SUP&gt; of OCT 2021 (WHERE DATE &amp;gt;= ‘01OCT2021’d)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Condition 2&lt;/P&gt;
&lt;P&gt;If today's date is greater than or equal to 1&lt;SUP&gt;st&lt;/SUP&gt; of NOV 2022 = table contains data within a period of 13 months&lt;/P&gt;
&lt;P&gt;(WHERE DATE &amp;gt;= INTNX(‘month’, XXX, -13, ‘B’)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Se my example&amp;nbsp; tables. I use variable row just to illustrate the rows I want.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 10:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790120#M252933</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2022-01-14T10:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change a WHERE/ or IF THEN-condition depending on which date it is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790122#M252934</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want,
set have;
if '01jan2022'd le today() le '31oct2022'd
then cutoff = '01oct2021'd,
else cutoff = intnx('month',today(),-13,'b');
if date ge cutoff;
drop cutoff;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jan 2022 10:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790122#M252934</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-14T10:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change a WHERE/ or IF THEN-condition depending on which date it is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790129#M252935</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Played around a bit with your code and it worked like a charm!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Kurt.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET generic_today=today()+780;
data want;
FORMAT generic_today Cutoff YYMMDD10.;
set have;
generic_today = &amp;amp;generic_today;
if '01jan2022'd le generic_today le '31oct2022'd
then cutoff = '01oct2021'd;
else cutoff = intnx('month',generic_today,-13,'b');
if date ge cutoff;
/*drop cutoff;*/
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 12:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790129#M252935</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2022-01-14T12:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change a WHERE/ or IF THEN-condition depending on which date it is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790167#M252951</link>
      <description>&lt;P&gt;I really hope that your program documentation discusses exactly why you have a +780 in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such magic numbers are one of the banes of the next person to use your code, or if you don't revisit it for a long time, especially if the macro variables are set somewhere not in close proximity to the code where it is used.&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/363831"&gt;@Pili1100&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Played around a bit with your code and it worked like a charm!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Kurt.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET generic_today=today()+780;
data want;
FORMAT generic_today Cutoff YYMMDD10.;
set have;
generic_today = &amp;amp;generic_today;
if '01jan2022'd le generic_today le '31oct2022'd
then cutoff = '01oct2021'd;
else cutoff = intnx('month',generic_today,-13,'b');
if date ge cutoff;
/*drop cutoff;*/
run;
&lt;/CODE&gt;&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>Fri, 14 Jan 2022 16:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790167#M252951</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-14T16:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I change a WHERE/ or IF THEN-condition depending on which date it is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790169#M252952</link>
      <description>&lt;P&gt;I was trying lots of different number so as to change the date, for the the geneteric_today date. +780 was the last one I tried&lt;/P&gt;
&lt;P&gt;Anything thing particular you think I should add?&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 16:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-change-a-WHERE-or-IF-THEN-condition-depending-on-which/m-p/790169#M252952</guid>
      <dc:creator>Pili1100</dc:creator>
      <dc:date>2022-01-14T16:09:57Z</dc:date>
    </item>
  </channel>
</rss>

