<?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 Sum Vertically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455003#M115039</link>
    <description>Try &lt;BR /&gt;    Group by QWHSSSID, SYSTEM_DATE&lt;BR /&gt;instead of &lt;BR /&gt;    Group by QWHSSSID, DATEPART(SMFTIME)&lt;BR /&gt;</description>
    <pubDate>Wed, 18 Apr 2018 02:14:04 GMT</pubDate>
    <dc:creator>ShenQicheng</dc:creator>
    <dc:date>2018-04-18T02:14:04Z</dc:date>
    <item>
      <title>How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454978#M115030</link>
      <description>&lt;P&gt;If&amp;nbsp;I have a field that's a datetime value, how do I correctly sum(time-part) using proc sql?&amp;nbsp; &amp;nbsp;I don't have a problem getting the 'timepart' out of the timestamp, but if I try to 'group by' with a 'sum' on that 'time value', I get the same number in every record for time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL doesn't seem to handle date/time arithmetic the same way SQL does on a DBMS.&amp;nbsp; &amp;nbsp;If this can't be done using Proc SQL, can someone recommend the next best method?&amp;nbsp; I need to hand off this program to a DBA, so I need something nice and clean that a DBA will understand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 00:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454978#M115030</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-18T00:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454980#M115031</link>
      <description>Can you provide a code sample and the results that can describe you problem?</description>
      <pubDate>Wed, 18 Apr 2018 01:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454980#M115031</guid>
      <dc:creator>ShenQicheng</dc:creator>
      <dc:date>2018-04-18T01:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454988#M115033</link>
      <description>&lt;P&gt;Depending on how you selected the data you would get either the GROUP variables + the summary statistics or you'll get all records plus the summary statistic repeated.&lt;/P&gt;
&lt;P&gt;Since you don't show your code we can't say what you did wrong. See the example below, and run them to the see the different forms of output.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table demo1 as
select *, mean(height) as avg_height
from sashelp.class
group by sex;
create table demo2 as
select sex, mean(height) as avg_height
from sashelp.class
group by sex;
quit;

proc print data=demo1;
proc print data=demo2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I've made some assumptions about your question because you didn't show any code. If&amp;nbsp;this doesn't answer your question, please include your code and log illustrating the issue. If you use the SASHELP data sets we can replicate your work as well on our machines to test a solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/205375"&gt;@alterman1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;If&amp;nbsp;I have a field that's a datetime value, how do I correctly sum(time-part) using proc sql?&amp;nbsp; &amp;nbsp;I don't have a problem getting the 'timepart' out of the timestamp, but if I try to 'group by' with a 'sum' on that 'time value', I get the same number in every record for time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc SQL doesn't seem to handle date/time arithmetic the same way SQL does on a DBMS.&amp;nbsp; &amp;nbsp;If this can't be done using Proc SQL, can someone recommend the next best method?&amp;nbsp; I need to hand off this program to a DBA, so I need something nice and clean that a DBA will understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 01:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454988#M115033</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-18T01:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454994#M115034</link>
      <description />
      <pubDate>Wed, 18 Apr 2018 01:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454994#M115034</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-18T01:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454995#M115035</link>
      <description>&lt;P&gt;The above attachment shows the data before summarization, after summerization, and the PROC SQL code I'm trying to summerize it with.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 01:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454995#M115035</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-18T01:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454996#M115036</link>
      <description>&lt;P&gt;Hi Reeza.&amp;nbsp; I've added my PRO SQL code and samples of my output before and after.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 01:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/454996#M115036</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-18T01:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455002#M115038</link>
      <description>&lt;P&gt;I think your error is logical not code, but I can't really tell because the variable names don't align with the data you've shown and scrolling between pages doesn't make it any easier to figure it out which variables are which.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a typical SQL query you would need to have all the GROUP BY variables included on your SELECT statement and all other variables must be summary. SAS doesn't require this, but if you don't do it, it returns every line.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please include your images and code directly into the forum and as text, not as screenshots, it makes it infinitely harder to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/205375"&gt;@alterman1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza.&amp;nbsp; I've added my PRO SQL code and samples of my output before and after.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 02:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455002#M115038</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-18T02:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455003#M115039</link>
      <description>Try &lt;BR /&gt;    Group by QWHSSSID, SYSTEM_DATE&lt;BR /&gt;instead of &lt;BR /&gt;    Group by QWHSSSID, DATEPART(SMFTIME)&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Apr 2018 02:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455003#M115039</guid>
      <dc:creator>ShenQicheng</dc:creator>
      <dc:date>2018-04-18T02:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455005#M115040</link>
      <description>&lt;P&gt;Reeza, I displayed the code the only way I can.&amp;nbsp; &amp;nbsp;I don't have any what of downloading the code into a text file or transferring the file with email or ftp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you look at my proc sql, there are 3 fields - SMFTIME which is the timestamp that I am extracting the date from and trying to group by.&amp;nbsp; QWHSSSID is the&amp;nbsp;other variable that appears in the group by clause.&amp;nbsp; They are the two fields I'm trying to summarize by.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;The third and last field is QPACTJST which is a time12.2 field.&amp;nbsp; This is the field that I want to sum using&amp;nbsp; QWHSSSID and DATEPART(SMFTIME) to group my data.&amp;nbsp; &amp;nbsp;If there is a logic error, I don't see it.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I tried to group by a string QWHSSSID and a DATE in DB2, this would work perfectly with just using a DATE column function against SMFTIME (which, again, is a timestamp column).&amp;nbsp; It looks like PROC SQL handles this differently and I've looked through a ton of content trying to find an example of someone summing a time field by some key.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 02:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455005#M115040</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-18T02:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455007#M115042</link>
      <description>&lt;P&gt;I grouped by QWHSSID and SYSTEMS_DATE and I still get the same result.&amp;nbsp; &amp;nbsp;CPU_TIME the same value in every row.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 02:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455007#M115042</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-18T02:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455009#M115044</link>
      <description>As Reeza said, please post your code directly into the forum in text format.</description>
      <pubDate>Wed, 18 Apr 2018 02:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455009#M115044</guid>
      <dc:creator>ShenQicheng</dc:creator>
      <dc:date>2018-04-18T02:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455010#M115045</link>
      <description>&lt;P&gt;I can't transfer it, so I typed it in.&amp;nbsp; Hopefully no typing errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OPTIONS PAGESIZE=40 LINESIZE=250 PAGENO=1 NOCENTER;&lt;/P&gt;&lt;P&gt;LIBNAME DETAIL;&lt;/P&gt;&lt;P&gt;PROC DATASETS LIBRARY=DETAIL;&lt;/P&gt;&lt;P&gt;DATA DB2ACCTP;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;SET DETAIL.DB2ACCTP;&lt;/P&gt;&lt;P&gt;PROC CONTENTS;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;SELECT&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; DATEPART(SMFTIME) AS SYSTEM_DATE FORMAT DATE 11.1,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; QWHSSSID AS SSID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; SUM(QPACTJST) AS CPU_TIME,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; COUNT(*)&lt;/P&gt;&lt;P&gt;FROM DB2ACCTP&lt;/P&gt;&lt;P&gt;WHERE QWHSSSID = 'DB2A'&lt;/P&gt;&lt;P&gt;GROUP BY SSID, SYSTEM_DATE&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 02:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455010#M115045</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-18T02:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455054#M115065</link>
      <description>&lt;P&gt;Since we've left the stone age of computing and the beasts understand lowercase perfectly well, there's no need anymore to keep capslock on in programming, which makes code easier for the eyes.&lt;/P&gt;
&lt;P&gt;With some made-up data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data db2acctp;
input smftime :e8601dt16. qwhsssid $ qpactjst;
cards;
2018-04-09T16:30 DB2A 3
2018-04-09T16:40 DB2A 4
2018-04-09T16:50 DB2A 2
2018-04-10T08:31 DB2A 2
2018-04-10T08:40 DB2A 3
;
run;

proc sql;
select
  datepart(smftime) as system_date format yymmddd10.,
  qwhsssid as ssid,
  sum(qpactjst) as cpu_time,
  count(*) as count
from db2acctp
where qwhsssid = 'DB2A'
group by ssid, system_date
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;system_date  ssid      cpu_time     count
-----------------------------------------
 2018-04-09  DB2A             9         3
 2018-04-10  DB2A             5         2
&lt;/PRE&gt;
&lt;P&gt;See my footnotes for preparing example data and posting code.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 07:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455054#M115065</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-18T07:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sum Vertically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455425#M115198</link>
      <description>&lt;P&gt;Thanks Kurt.&amp;nbsp; I appreciate the help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ron&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 00:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Sum-Vertically/m-p/455425#M115198</guid>
      <dc:creator>alterman1</dc:creator>
      <dc:date>2018-04-19T00:27:05Z</dc:date>
    </item>
  </channel>
</rss>

