<?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: Dynamic coding solution for Year over Year Comparisons of a daily variable like Sales, Claims in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-coding-solution-for-Year-over-Year-Comparisons-of-a/m-p/816386#M322226</link>
    <description>&lt;P&gt;Apologies if this posts twice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response and please accept my apologies for any confusion.&amp;nbsp; Please let me provide a little more background around the problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I am creating a simple monthly report showing retail sales for 2021 and 2022 (all calendar based).&amp;nbsp; The problem is that simply comparing the month to a prior year can sometimes be skewed say if Mar-22 has 5 Saturdays vs. 4 Saturday’s in Mar-21.&amp;nbsp; Retail businesses deal with this problem where working days can be different for the same month in the current and prior year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently my solution is not very elegant, and I was curious if there is a dynamic solution.&amp;nbsp; Starting with the 1st Monday of the year, I reclassify the month based on the actual date where needed so there is a consistent number of working days and thus weeks when looking at any given month.&amp;nbsp; The sample code belows shows how I handle this in May-21 and May-22.&amp;nbsp; There is no data reported for weekends (Sat – Sun reported on Monday).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Code&lt;/STRONG&gt;&lt;/U&gt;:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA GRAPEAPE;&lt;BR /&gt;INPUT DATE1 MMDDYY10.&lt;BR /&gt;PMON&lt;BR /&gt;PYEAR&lt;BR /&gt;SALES&lt;BR /&gt;;&lt;BR /&gt;FORMAT DATE1 MMDDYY10.&lt;BR /&gt;PMON Z2.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;05 27 2021 05 2021 1000&lt;BR /&gt;05 28 2021 05 2021 2000&lt;BR /&gt;05 31 2021 05 2021 3000&lt;BR /&gt;06 01 2021 06 2021 1100&lt;BR /&gt;06 02 2021 06 2021 1200&lt;BR /&gt;06 03 2021 06 2021 1300&lt;BR /&gt;06 04 2021 06 2021 1400&lt;BR /&gt;05 27 2022 05 2022 1111&lt;BR /&gt;05 30 2022 05 2022 1111&lt;BR /&gt;05 31 2022 05 2022 1133&lt;BR /&gt;06 01 2022 06 2022 1155&lt;BR /&gt;06 02 2022 06 2022 1177&lt;BR /&gt;06 03 2022 06 2022 2311&lt;BR /&gt;06 04 2022 06 2022 2322&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA = GRAPEAPE;&lt;BR /&gt;TITLE 'DAILY SALES';&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;DATA SPEEDRACER;&lt;BR /&gt;SET GRAPEAPE;&lt;/P&gt;&lt;P&gt;ATTRIB NEWMON FORMAT=Z2.;&lt;BR /&gt;NEWMON=PMON;&lt;BR /&gt;IF DATE1 IN('31MAY2021'D) THEN NEWMON=6;&lt;BR /&gt;ELSE IF DATE1 IN('30MAY2022'D,'31MAY2022'D) THEN NEWMON=6;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC PRINT DATA = SPEEDRACER;&lt;BR /&gt;TITLE 'DAILY SALES';&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;TITLE1 'SALES BY MONTH';&lt;BR /&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;SELECT PYEAR&lt;BR /&gt;,PMON&lt;BR /&gt;,SUM(SALES) AS TOTSALES&lt;BR /&gt;FROM SPEEDRACER&lt;BR /&gt;GROUP BY PYEAR, PMON;&lt;/P&gt;&lt;P&gt;SELECT PYEAR&lt;BR /&gt;,NEWMON&lt;BR /&gt;,SUM(SALES) AS TOTSALES&lt;BR /&gt;FROM SPEEDRACER&lt;BR /&gt;GROUP BY PYEAR, NEWMON;&lt;BR /&gt;QUIT;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jun 2022 18:50:27 GMT</pubDate>
    <dc:creator>steveocaffey</dc:creator>
    <dc:date>2022-06-03T18:50:27Z</dc:date>
    <item>
      <title>Dynamic coding solution for Year over Year Comparisons of a daily variable like Sales, Claims</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-coding-solution-for-Year-over-Year-Comparisons-of-a/m-p/816260#M322158</link>
      <description>&lt;P&gt;I am hoping some of you smart folks can help me with a dynamic coding solution that is not hard coded.&amp;nbsp; My problem is that I am trying to a monthly comparison of sales year over year.&amp;nbsp; The underlying data has data reported Monday through Friday.&amp;nbsp; The inherent problem is that calendar weeks are different each year where part of the first or last week spans into the following month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The end-goal is to align the same number of working days for any given month.&amp;nbsp; Currently I am using a hard-coded solution that increments the actual month based by +1 or -1 based on the actual date.&amp;nbsp; A couple of examples; (1)&amp;nbsp; 05/30/21, 05/30/22 and 05/31/22 are hard coded so the month reflects June or ‘06’ (2)&amp;nbsp; 04/01/21, 04/02/21 and 02/28/22, 04/01/22 are hard coded so the month reflects March or ‘03’.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been trying to use the new retail dates ‘R445MON’ coupled with the INTNX function, but I don’t believe this is a solution.&amp;nbsp; I am not able to get the same result as my hard coded solution.&amp;nbsp; I have also search for end-users with a similar problem to no avail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in-advance for any help.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 21:19:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-coding-solution-for-Year-over-Year-Comparisons-of-a/m-p/816260#M322158</guid>
      <dc:creator>steveocaffey</dc:creator>
      <dc:date>2022-06-02T21:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic coding solution for Year over Year Comparisons of a daily variable like Sales, Claims</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-coding-solution-for-Year-over-Year-Comparisons-of-a/m-p/816264#M322162</link>
      <description>&lt;P&gt;Some example data and result of your "hard coding" might be helpful.&lt;/P&gt;
&lt;P&gt;You say "monthly" and then get into "weeks" without quite covering in a bit of detail what your rules are. What kind of "month" comparison are you looking to do? Total? Mean daily? something else?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 21:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-coding-solution-for-Year-over-Year-Comparisons-of-a/m-p/816264#M322162</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-02T21:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic coding solution for Year over Year Comparisons of a daily variable like Sales, Claims</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-coding-solution-for-Year-over-Year-Comparisons-of-a/m-p/816386#M322226</link>
      <description>&lt;P&gt;Apologies if this posts twice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response and please accept my apologies for any confusion.&amp;nbsp; Please let me provide a little more background around the problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I am creating a simple monthly report showing retail sales for 2021 and 2022 (all calendar based).&amp;nbsp; The problem is that simply comparing the month to a prior year can sometimes be skewed say if Mar-22 has 5 Saturdays vs. 4 Saturday’s in Mar-21.&amp;nbsp; Retail businesses deal with this problem where working days can be different for the same month in the current and prior year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently my solution is not very elegant, and I was curious if there is a dynamic solution.&amp;nbsp; Starting with the 1st Monday of the year, I reclassify the month based on the actual date where needed so there is a consistent number of working days and thus weeks when looking at any given month.&amp;nbsp; The sample code belows shows how I handle this in May-21 and May-22.&amp;nbsp; There is no data reported for weekends (Sat – Sun reported on Monday).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Code&lt;/STRONG&gt;&lt;/U&gt;:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA GRAPEAPE;&lt;BR /&gt;INPUT DATE1 MMDDYY10.&lt;BR /&gt;PMON&lt;BR /&gt;PYEAR&lt;BR /&gt;SALES&lt;BR /&gt;;&lt;BR /&gt;FORMAT DATE1 MMDDYY10.&lt;BR /&gt;PMON Z2.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;05 27 2021 05 2021 1000&lt;BR /&gt;05 28 2021 05 2021 2000&lt;BR /&gt;05 31 2021 05 2021 3000&lt;BR /&gt;06 01 2021 06 2021 1100&lt;BR /&gt;06 02 2021 06 2021 1200&lt;BR /&gt;06 03 2021 06 2021 1300&lt;BR /&gt;06 04 2021 06 2021 1400&lt;BR /&gt;05 27 2022 05 2022 1111&lt;BR /&gt;05 30 2022 05 2022 1111&lt;BR /&gt;05 31 2022 05 2022 1133&lt;BR /&gt;06 01 2022 06 2022 1155&lt;BR /&gt;06 02 2022 06 2022 1177&lt;BR /&gt;06 03 2022 06 2022 2311&lt;BR /&gt;06 04 2022 06 2022 2322&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA = GRAPEAPE;&lt;BR /&gt;TITLE 'DAILY SALES';&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;DATA SPEEDRACER;&lt;BR /&gt;SET GRAPEAPE;&lt;/P&gt;&lt;P&gt;ATTRIB NEWMON FORMAT=Z2.;&lt;BR /&gt;NEWMON=PMON;&lt;BR /&gt;IF DATE1 IN('31MAY2021'D) THEN NEWMON=6;&lt;BR /&gt;ELSE IF DATE1 IN('30MAY2022'D,'31MAY2022'D) THEN NEWMON=6;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC PRINT DATA = SPEEDRACER;&lt;BR /&gt;TITLE 'DAILY SALES';&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;TITLE1 'SALES BY MONTH';&lt;BR /&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;SELECT PYEAR&lt;BR /&gt;,PMON&lt;BR /&gt;,SUM(SALES) AS TOTSALES&lt;BR /&gt;FROM SPEEDRACER&lt;BR /&gt;GROUP BY PYEAR, PMON;&lt;/P&gt;&lt;P&gt;SELECT PYEAR&lt;BR /&gt;,NEWMON&lt;BR /&gt;,SUM(SALES) AS TOTSALES&lt;BR /&gt;FROM SPEEDRACER&lt;BR /&gt;GROUP BY PYEAR, NEWMON;&lt;BR /&gt;QUIT;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 18:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-coding-solution-for-Year-over-Year-Comparisons-of-a/m-p/816386#M322226</guid>
      <dc:creator>steveocaffey</dc:creator>
      <dc:date>2022-06-03T18:50:27Z</dc:date>
    </item>
  </channel>
</rss>

