<?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: calculate YTD for moving month vs current year YTD by disease in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914681#M360433</link>
    <description>&lt;P&gt;Here is my revised desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bijayadhikar_0-1707225368863.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93304iDBBC4D5C66144EDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bijayadhikar_0-1707225368863.png" alt="bijayadhikar_0-1707225368863.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;5-year average year-to-date COUNT = all 5 Jan/5&lt;/P&gt;</description>
    <pubDate>Tue, 06 Feb 2024 13:18:30 GMT</pubDate>
    <dc:creator>bijayadhikar</dc:creator>
    <dc:date>2024-02-06T13:18:30Z</dc:date>
    <item>
      <title>calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914587#M360395</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to calculate last year's YDT (i.e. 2023 Jan), last 5 year's YTD (i.e. 2019-2023 Jan), last 5 year's annual average (i.e. average 2019-2023 Jan) and &lt;STRONG&gt;compare with this year's YTD counts&lt;/STRONG&gt; (i.e. 2024 Jan) to see if this year's YTD counts are high.&amp;nbsp; Once we have Feb full data we will calc YTD accordingly.&amp;nbsp;Here is the dataset, thanks in advance for your help.&lt;/P&gt;
&lt;P&gt;DATA SHOWN ONLY FOR 3 MONTHS HERE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;infile datalines delimiter=','; &lt;BR /&gt;input disease$ year month tot;&lt;/P&gt;
&lt;P&gt;cards;&lt;BR /&gt;A,2019,1,7&lt;BR /&gt;A,2019,2,9&lt;BR /&gt;A,2019,3,13&lt;BR /&gt;A,2020,1,7&lt;BR /&gt;A,2020,2,10&lt;BR /&gt;A,2020,3,9&lt;BR /&gt;A,2021,1,8&lt;BR /&gt;A,2021,2,16&lt;BR /&gt;A,2021,3,6&lt;BR /&gt;A,2022,1,8&lt;BR /&gt;A,2022,2,5&lt;BR /&gt;A,2022,3,7&lt;BR /&gt;A,2023,1,8&lt;BR /&gt;A,2023,2,4&lt;BR /&gt;A,2023,3,11&lt;BR /&gt;B,2019,1,11&lt;BR /&gt;B,2019,2,2&lt;BR /&gt;B,2019,3,5&lt;BR /&gt;B,2020,1,3&lt;BR /&gt;B,2020,2,6&lt;BR /&gt;B,2020,3,7&lt;BR /&gt;B,2021,1,2&lt;BR /&gt;B,2021,2,2&lt;BR /&gt;B,2021,3,1&lt;BR /&gt;B,2022,1,4&lt;BR /&gt;B,2022,2,4&lt;BR /&gt;B,2022,3,1&lt;BR /&gt;B,2023,1,2&lt;BR /&gt;B,2023,2,11&lt;BR /&gt;B,2023,3,5&lt;BR /&gt;A,2024,1,4&lt;BR /&gt;B,2024,1,7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Expected OUTPUT&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bijayadhikar_0-1707171954806.png" style="width: 432px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93279i08C15BA29E613361/image-dimensions/432x41?v=v2" width="432" height="41" role="button" title="bijayadhikar_0-1707171954806.png" alt="bijayadhikar_0-1707171954806.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 22:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914587#M360395</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2024-02-05T22:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914607#M360404</link>
      <description>Is your desired shown correctly for the headings? What value does YTD 2019-2023 provide when the period is not same as the average? I would expect that to be the average. And you want to include the average including the current year? or is that a typo?</description>
      <pubDate>Mon, 05 Feb 2024 23:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914607#M360404</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-05T23:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914616#M360408</link>
      <description>&lt;P&gt;Thank you Reeza. Likely I made a mistake. My objective is to produce 2024 monthly report. Each month of 2024 will be compared avg of last 5 years of that month. i.e. JAN this year will be compared with five previous January divided by 5, so I get historical average to compare with this year. Here is an example report I found and trying to produce automated report that I will schedule in SAS Management Console. &lt;STRONG&gt;Basically I need to figure out 2nd last column of the report below using macro year and month,&lt;/STRONG&gt; so that the it will be good next year and so on. You can ignore other YTD columns. I need "5-year&amp;nbsp;average&amp;nbsp;year-to-date&amp;nbsp;COUNT" column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://Thank you Reeza. Likely I made a mistake. My objective is to produce 2024 monthly report. Each month of 2024 will be compared avg of last 5 years of that month. i.e. JAN this year will be compared with five previous January divided by 5, so I get historical average to compare with this year.   Here is an example report I found and trying to produce automated report that I will schedule in SAS Management Console.  Basically I need to figure out 2nd last column using macro year and month, so that the it will be good next year as well.  https://www.publichealthontario.ca/-/media/Documents/Surveillance-Reports/Infectious/2022/surveillance-report-infectious-diseases-jan-dec-2022.pdf?rev=5549ab2c6b25405cbcf7caa18e07fb96&amp;amp;sc_lang=en" target="_self"&gt;https://www.publichealthontario.ca/-/media/Documents/Surveillance-Reports/Infectious/2022/surveillance-report-infectious-diseases-jan-dec-2022.pdf?rev=5549ab2c6b25405cbcf7caa18e07fb96&amp;amp;sc_lang=en&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 01:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914616#M360408</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2024-02-06T01:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914681#M360433</link>
      <description>&lt;P&gt;Here is my revised desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bijayadhikar_0-1707225368863.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93304iDBBC4D5C66144EDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bijayadhikar_0-1707225368863.png" alt="bijayadhikar_0-1707225368863.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;5-year average year-to-date COUNT = all 5 Jan/5&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 13:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914681#M360433</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2024-02-06T13:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914722#M360451</link>
      <description>&lt;P&gt;Assuming you have no missing data this is one way. If you do have missing data, you will need another method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited to reflect&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;comment (thanks!)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=have;
    by disease month year;
run;

proc transpose data=have out=wide prefix=YEAR;
    by disease month;
    id year;
    var tot;
run;

data want;
    set wide;
    by disease month;
    retain running_total;
     if first.disease then running_total=0;
    total=sum(of year2019-year2023);
    running_total+total;
    YTD_AVG_2019_2023=running_total/5;
    drop running_total total _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/346623"&gt;@bijayadhikar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here is my revised desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bijayadhikar_0-1707225368863.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93304iDBBC4D5C66144EDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bijayadhikar_0-1707225368863.png" alt="bijayadhikar_0-1707225368863.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;5-year average year-to-date COUNT = all 5 Jan/5&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 18:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914722#M360451</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-06T18:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914733#M360459</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&amp;nbsp;This works for me. Very apricated.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 18:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914733#M360459</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2024-02-06T18:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914737#M360463</link>
      <description>I think a&lt;BR /&gt;&lt;BR /&gt;if first.disease then call missing(running_total) ;&lt;BR /&gt;&lt;BR /&gt;statement is needed to prevent including prior diseases in the ytd values for the current disease.</description>
      <pubDate>Tue, 06 Feb 2024 18:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914737#M360463</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-02-06T18:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: calculate YTD for moving month vs current year YTD by disease</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914850#M360515</link>
      <description>Noted. Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;</description>
      <pubDate>Wed, 07 Feb 2024 13:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-YTD-for-moving-month-vs-current-year-YTD-by-disease/m-p/914850#M360515</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2024-02-07T13:04:14Z</dc:date>
    </item>
  </channel>
</rss>

