<?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 Sum of variables based on date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/948959#M371256</link>
    <description>&lt;P&gt;I have a wide form dataset in which each patient has multiple MME measures (MME_1 - MME_153) and a corresponding date (Order_Date_1 - Order_Date_153).&amp;nbsp; Each patient has a pre and post intervention period, based on the variable index_date.&amp;nbsp; I need to create a variable that is the sum of all MME measures in the pre period and another variable that is the sum of all MME measures in the post period.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2024 19:12:18 GMT</pubDate>
    <dc:creator>CJK7</dc:creator>
    <dc:date>2024-10-24T19:12:18Z</dc:date>
    <item>
      <title>Sum of variables based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/948959#M371256</link>
      <description>&lt;P&gt;I have a wide form dataset in which each patient has multiple MME measures (MME_1 - MME_153) and a corresponding date (Order_Date_1 - Order_Date_153).&amp;nbsp; Each patient has a pre and post intervention period, based on the variable index_date.&amp;nbsp; I need to create a variable that is the sum of all MME measures in the pre period and another variable that is the sum of all MME measures in the post period.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 19:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/948959#M371256</guid>
      <dc:creator>CJK7</dc:creator>
      <dc:date>2024-10-24T19:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/948962#M371258</link>
      <description>&lt;P&gt;This is incredibly easy with a long data set and PROC SUMMARY. You can use PROC TRANSPOSE to create the long data set. If you provide a small example of the data with say 10 patients, 3 variables and the corresponding 3 dates and the pre and post intervention dates, I can provide code. Use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; to provide data as SAS Data step code. Do not attach files or show us screen captures.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 19:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/948962#M371258</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-24T19:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/948986#M371263</link>
      <description>&lt;P&gt;You can use two arrays, each with 153 elements - one array for the dates, and one for the mme values.&amp;nbsp; Then just iterate through the 153 elements of each array, test the date and add the mme to the pre- or post- summary value, as appropriate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array odate order_date_1 - order_date_153;
  array mme   mme_1        - mme_153;
  do over odate;
    if odate&amp;gt;index_date then post_sum=sum(post_sum,mme);
    else if odate&amp;gt;. then pre_sum=sum(pre_sum,mme);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2024 22:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/948986#M371263</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-10-24T22:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/949468#M371407</link>
      <description>&lt;P&gt;I wasn't able to provide the example data, but your comment did put me on the right path.&amp;nbsp; I was able to manipulate the data as needed in long form, then transpose back to wide form.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 13:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-based-on-date/m-p/949468#M371407</guid>
      <dc:creator>CJK7</dc:creator>
      <dc:date>2024-10-30T13:07:45Z</dc:date>
    </item>
  </channel>
</rss>

