<?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 to convert/sum minutely data to hourly data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587134#M167657</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258831"&gt;@luanx017&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has said, the first step just creates sample data serving to &lt;EM&gt;emulate&lt;/EM&gt; the input data you've described, so that the proposed solution could be tested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID is an equivalent of the categorical variable which in your real data set identifies different participants. If your variable serving this purpose is called, say, Participant, it doesn't matter, and nor does its data type and length. Just plug it in the second step's code to see the effect.&amp;nbsp;Likewise, you variable holding the minute counts is surely not called mm_count; but again, it doesn't matter. Just plug &lt;EM&gt;your&lt;/EM&gt; variable holding the minute count in the code and then test it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Sep 2019 04:40:33 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-09-09T04:40:33Z</dc:date>
    <item>
      <title>How to convert/sum minutely data to hourly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587001#M167580</link>
      <description>&lt;P&gt;I have a longitudinal data set where one participant have counts for each minute for 24 hours a day and seven days in total.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am just wonder How could I aggregate the data into per hour.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Sep 2019 22:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587001#M167580</guid>
      <dc:creator>luanx017</dc:creator>
      <dc:date>2019-09-07T22:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert/sum minutely data to hourly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587003#M167581</link>
      <description>&lt;P&gt;Assuming that the time is an actual SAS time or datetime value, you can apply a format to the time value such as the HOUR. format and then apply PROC SUMMARY to the data to aggregate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
    class time;
    var count;
    format time hour.;
    output out=sums sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Sep 2019 22:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587003#M167581</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-07T22:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert/sum minutely data to hourly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587032#M167598</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258831"&gt;@luanx017&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;My understanding from your description is all you have in your input data set to rely upon is the ID variable and the count for each minute; and that your data set is strictly structured with 60*24*7 records per ID. Though it would definitely help if each record were marked with its datetime value (see the response by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;in this case), the data set structure itself is mathematically sufficient to categorize it into larger time intervals and do the required summation. So, suppose it is structured as follows (note that only ID and mm_count are kept to emulate the assumed paucity of your input data):&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (keep = ID mm_count) ;               
  do ID = "A", "B" ;                           
    do dd = 1 to 7 ;                           
      do hh = 1 to 24 ;                        
        do mm = 1 to 60 ;                      
          mm_count = floor (ranuni (1) * 100) ;
          output ;                             
        end ;                                  
      end ;                                    
    end ;                                      
  end ;                                        
run ;                                          
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Having only ID and mm_count to work with, you summarization can be done as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;                                                
  create table want as                                 
  select id                                               
       , 1 + mod (ceil (monotonic() / 1440) - 1,  7) as dd
       , 1 + mod (ceil (monotonic() /   60) - 1, 24) as hh
       , sum (mm_count) as hh_count                       
  from   have                                             
  group  id, dd, hh                                       
  ;                                                       
quit ;                                                    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Creating DD and including it in the GROUP clause is optional; just methought it would be nice to have a day variable in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 03:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587032#M167598</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-08T03:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert/sum minutely data to hourly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587080#M167624</link>
      <description>&lt;P&gt;Thank you so much for the reply. The problem is I have thousands of participants and each of them have data counts per min for 24 hours and 7 days. I didn't quite understand the "ID= A B" part in the codes. Thanks again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 15:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587080#M167624</guid>
      <dc:creator>luanx017</dc:creator>
      <dc:date>2019-09-08T15:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert/sum minutely data to hourly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587081#M167625</link>
      <description>&lt;P&gt;Thank you so much for your reply! I will definitely try this next time when I have the SAS time. Thanks again!&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 15:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587081#M167625</guid>
      <dc:creator>luanx017</dc:creator>
      <dc:date>2019-09-08T15:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert/sum minutely data to hourly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587084#M167627</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258831"&gt;@luanx017&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you so much for the reply. The problem is I have thousands of participants and each of them have data counts per min for 24 hours and 7 days. I didn't quite understand the "ID= A B" part in the codes. Thanks again.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because you did not provide any example data the first data step is just to create an example dataset.&amp;nbsp; The second part of the answer is the code you should try to modify to work for your real data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: If you do not understand how the DO statement works then refer to the SAS manual. You can find it on-line.&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2019 16:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587084#M167627</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-08T16:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert/sum minutely data to hourly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587134#M167657</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258831"&gt;@luanx017&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has said, the first step just creates sample data serving to &lt;EM&gt;emulate&lt;/EM&gt; the input data you've described, so that the proposed solution could be tested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID is an equivalent of the categorical variable which in your real data set identifies different participants. If your variable serving this purpose is called, say, Participant, it doesn't matter, and nor does its data type and length. Just plug it in the second step's code to see the effect.&amp;nbsp;Likewise, you variable holding the minute counts is surely not called mm_count; but again, it doesn't matter. Just plug &lt;EM&gt;your&lt;/EM&gt; variable holding the minute count in the code and then test it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 04:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-sum-minutely-data-to-hourly-data/m-p/587134#M167657</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-09T04:40:33Z</dc:date>
    </item>
  </channel>
</rss>

