<?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: Function to get equivalent (homologous) dates from another year in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622291#M19751</link>
    <description>&lt;P&gt;Does this work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;40         data _null_;
41            do d1 = '05JAN2019'd to '05JAN2020'd by 1;
42               y = intnx('Week',d1,52,'S');
43               put (_all_)(=weekdate.);
44               end;
45            run;

d1=Saturday, January 5, 2019 y=Saturday, January 4, 2020
d1=Sunday, January 6, 2019 y=Sunday, January 5, 2020
d1=Monday, January 7, 2019 y=Monday, January 6, 2020
d1=Tuesday, January 8, 2019 y=Tuesday, January 7, 2020
d1=Wednesday, January 9, 2019 y=Wednesday, January 8, 2020
d1=Thursday, January 10, 2019 y=Thursday, January 9, 2020
d1=Friday, January 11, 2019 y=Friday, January 10, 2020
d1=Saturday, January 12, 2019 y=Saturday, January 11, 2020
d1=Sunday, January 13, 2019 y=Sunday, January 12, 2020&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Feb 2020 19:56:46 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2020-02-04T19:56:46Z</dc:date>
    <item>
      <title>Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622277#M19745</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to structure a base that compares the values day by day from last year (2019) with the equivalent days from this year (2020).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that these days must be equivalent not in a numerical form, but considering the weeks and weekdays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example: 01/05/2019 was the first Saturday from January, so in 2020 I need to compare it with 01/04/2019 (first Saturday from January in 2019).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any function that calculates these dates automatically?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 19:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622277#M19745</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2020-02-04T19:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622287#M19748</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267853"&gt;@Renan_Crepaldi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you should have a look at the following functions: Intck() and Intnx()&lt;/P&gt;
&lt;P&gt;best,&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 19:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622287#M19748</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-04T19:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622289#M19749</link>
      <description>The intnx function will give you what you want (mostly).</description>
      <pubDate>Tue, 04 Feb 2020 19:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622289#M19749</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2020-02-04T19:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622291#M19751</link>
      <description>&lt;P&gt;Does this work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;40         data _null_;
41            do d1 = '05JAN2019'd to '05JAN2020'd by 1;
42               y = intnx('Week',d1,52,'S');
43               put (_all_)(=weekdate.);
44               end;
45            run;

d1=Saturday, January 5, 2019 y=Saturday, January 4, 2020
d1=Sunday, January 6, 2019 y=Sunday, January 5, 2020
d1=Monday, January 7, 2019 y=Monday, January 6, 2020
d1=Tuesday, January 8, 2019 y=Tuesday, January 7, 2020
d1=Wednesday, January 9, 2019 y=Wednesday, January 8, 2020
d1=Thursday, January 10, 2019 y=Thursday, January 9, 2020
d1=Friday, January 11, 2019 y=Friday, January 10, 2020
d1=Saturday, January 12, 2019 y=Saturday, January 11, 2020
d1=Sunday, January 13, 2019 y=Sunday, January 12, 2020&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 19:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622291#M19751</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-02-04T19:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622342#M19755</link>
      <description>&lt;P&gt;I am not totally clear about your question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;The problem is that these days must be equivalent not in a numerical form, but considering the weeks and weekdays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: 01/05/2019 was the first Saturday from January, so in 2020 I need to compare it with 01/04/2019 (first Saturday from January in 2019).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any function that calculates these dates automatically?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, 1/1/2019&amp;nbsp; was the first TUESDAY of 2019, but the first Tuesday of 2020 was 1/7/2019.&amp;nbsp; That means while the first Tuesday of 2019 precedes the first Saturday of 2019, it's the opposite for 2020:&amp;nbsp; the first Saturday precedes the first Tuesday.&amp;nbsp; Is this what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want the 52 week interval provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;.&amp;nbsp; Just remember it would map Jan 1 to Dec 31&amp;nbsp; (or map to Dec 30 for leap years).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;z&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 02:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622342#M19755</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-05T02:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622355#M19756</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; how about&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NWKDOM(n, weekday, month, year) &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Feb 2020 03:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622355#M19756</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-02-05T03:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622357#M19757</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; how about&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NWKDOM(n, weekday, month, year) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the OP is really asking to map (say) the i'th Fri of 2019 to the i'th Fri of 2020, I don't see how NWKDOM would work, because it utilizes month as an argument.&amp;nbsp; For example the 5th Fri of 2019 is in February, but the 5th Fri of 2020 is in Jan.&amp;nbsp; it would be nice if there were a NWKDOY(n,weekday,year) function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The closest I can come to is (for 365-day years) add 52 weeks as per you suggestion, and add one more week whenever the date-in-hand is the same weekday as 01JAN of that year:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do d1='01jan2019'd to '30dec2019'd;
    d2=intnx('week',d1,52,'s');
    if weekday(d1)=weekday("01jan2019"d) then d2=d2+7;
    put (d:) (=weekdate. @40);
  end;
run;


   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The loop only goes to 30DEC2019 because 2019 has 53 Tuesdays (the last one on 31dec2019), but 2020 only has 52 Tuesdays, there is no 53rd Tuesday.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, that doesn't take care of leap years, in which&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;the extra week is applied to dates which are the same weekday as either 01JAN or 02JAN, and&lt;/LI&gt;
&lt;LI&gt;you would have to stop at 29DEC of the year in question.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267853"&gt;@Renan_Crepaldi&lt;/a&gt; &amp;nbsp; Which is it that you are looking for?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 05:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622357#M19757</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-05T05:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Function to get equivalent (homologous) dates from another year</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622415#M19775</link>
      <description>&lt;P&gt;Wow, guys! Thanks for this many replies!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;You got it right! The function I was looking for was to get the equivalent (homologous) dates for 2020 by comparing it to 2019.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After thinking about it a bit more, a solution I came across was to extract the week and weekday of each day on 2019, and use a second table with the same infos of 2020 plus the dates itselves. Then I made a join between these tables, bringing the equivalent date for each week/weekday of 2020.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure if this way has any flaws, but I think I'll try to use the script you suggested to compare.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, thanks very much to everyone that helped!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Renan Crepaldi&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 12:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Function-to-get-equivalent-homologous-dates-from-another-year/m-p/622415#M19775</guid>
      <dc:creator>Renan_Crepaldi</dc:creator>
      <dc:date>2020-02-05T12:14:57Z</dc:date>
    </item>
  </channel>
</rss>

