<?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: Sum variable on different rows within id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842037#M332942</link>
    <description>&lt;P&gt;How was indiff calculated?&lt;/P&gt;</description>
    <pubDate>Wed, 02 Nov 2022 08:27:00 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-11-02T08:27:00Z</dc:date>
    <item>
      <title>Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842033#M332938</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
  create table solution as
  select lopenummer, daydiff , indiff, min, maks, sum(daydiff) as sum_daydiff 

  from   want2
  group by lopenummer , indiff;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to sum number of days within each ID and indiff, but this does not work. I only got&amp;nbsp;&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="user40_0-1667375750460.png" style="width: 617px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76864i8518BC867C3932E9/image-dimensions/617x148?v=v2" width="617" height="148" role="button" title="user40_0-1667375750460.png" alt="user40_0-1667375750460.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But the last row should have sum daydiff to 626 and not 85, 39 and 502 in three different rows. How can i get this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 07:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842033#M332938</guid>
      <dc:creator>user40</dc:creator>
      <dc:date>2022-11-02T07:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842035#M332940</link>
      <description>&lt;P&gt;Either indiff or lopenummer is not exactly equal across the three rows. My guess is that indiff is a calculated column and not exactly equal.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 08:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842035#M332940</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-02T08:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842036#M332941</link>
      <description>&lt;P&gt;It is equal.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 08:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842036#M332941</guid>
      <dc:creator>user40</dc:creator>
      <dc:date>2022-11-02T08:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842037#M332942</link>
      <description>&lt;P&gt;How was indiff calculated?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 08:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842037#M332942</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-02T08:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842038#M332943</link>
      <description>&lt;P&gt;Indiff (days for each ami incidence for example) is a fast numeric variable and are not calculated. This variable is variable that are the same for the same incidence in each case.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 08:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842038#M332943</guid>
      <dc:creator>user40</dc:creator>
      <dc:date>2022-11-02T08:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842039#M332944</link>
      <description>&lt;P&gt;Ok. Either that or you have to include min, max and so on in your group by clause.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't run your code because you did not post any sample data to work with.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 08:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842039#M332944</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-02T08:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842064#M332957</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="user40_0-1667390390985.png" style="width: 637px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76868i3B7E6AE513194DBC/image-dimensions/637x247?v=v2" width="637" height="247" role="button" title="user40_0-1667390390985.png" alt="user40_0-1667390390985.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to sum daydiff variable in respect for lopenummer and indiff. Then I have this dataset,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to sum the daydiff variable regards group by lopenummer variable and indiff variable. I thinked that this would be like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql; 
create table want as 
select lopenummer, indiff, min , maks, daydiff, 
from test 
order by lopenummer , indiff; 
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But this do not work. What is wrong in my code?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 12:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842064#M332957</guid>
      <dc:creator>user40</dc:creator>
      <dc:date>2022-11-02T12:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842066#M332959</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432803"&gt;@user40&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="user40_0-1667390390985.png" style="width: 637px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76868i3B7E6AE513194DBC/image-dimensions/637x247?v=v2" width="637" height="247" role="button" title="user40_0-1667390390985.png" alt="user40_0-1667390390985.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try to sum daydiff variable in respect for lopenummer and indiff. Then I have this dataset,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to sum the daydiff variable regards group by lopenummer variable and indiff variable. I thinked that this would be like this:&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Would you please be so kind as to provide WORKING code for your data. This code doesn't work for a number of reasons, including a missing semi-colon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;proc sql; 
create table want as 
select lopenummer, indiff, min , maks, daydiff, 
from test 
order by lopenummer , indiff; 
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But this do not work. What is wrong in my code?&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get an error in the LOG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1076  proc sql;
1077  create table want as
1078  select lopenummer, indiff, min , maks, daydiff,
1079  from test
           ----
           22
           76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &amp;amp;, (, *, **, +, ',', -, '.', /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, AS,
              BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, LET, LIKE, LT, LTT, NE,
              NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

1080  order by lopenummer , indiff;
1081  quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;so if you fix that by removing the semi-colon after daydiff, does it work then?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 12:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842066#M332959</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-02T12:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842068#M332960</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql; 
create table want as 
select lopenummer, indiff, min , maks, daydiff 
from test 
order by lopenummer , indiff; 
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now then?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 12:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842068#M332960</guid>
      <dc:creator>user40</dc:creator>
      <dc:date>2022-11-02T12:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842070#M332961</link>
      <description>&lt;P&gt;Reading the thread again, perhaps you want (instead of your SQL code) this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=test nway;
    class lopenummer;
    var indiff min maks daydiff;
    output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but as I don't have working data, I can't be sure that provides the answer you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 12:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842070#M332961</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-02T12:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sum variable on different rows within id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842075#M332966</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432803"&gt;@user40&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data test; 
input lopenummer , indiff, min maks, daydiff 
ID1,  6495, 6130, 6860,  614 
ID2 7739, 7374, 8104, 19 
ID3, 9478, 9113, 9843, 85
ID3, 9478, 9113, 9843, 39
ID3, 9478, 9113, 9843, 502;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Obviously, you did not actually run the code for TEST, a required step to meet the criterion that it is WORKING code. Please fix all the errors.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 12:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-variable-on-different-rows-within-id/m-p/842075#M332966</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-02T12:33:10Z</dc:date>
    </item>
  </channel>
</rss>

