<?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: By group summary of distributed values in the variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844951#M334049</link>
    <description>Thank you.</description>
    <pubDate>Thu, 17 Nov 2022 19:27:47 GMT</pubDate>
    <dc:creator>webart999ARM</dc:creator>
    <dc:date>2022-11-17T19:27:47Z</dc:date>
    <item>
      <title>By group summary of distributed values in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844947#M334045</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I came up with a quick and simple question at first glance.&lt;/P&gt;
&lt;P&gt;But I am struggling with optimal solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the dataset (part of it)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dataset for question.PNG" style="width: 483px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77414iE550975F58B1E87B/image-size/large?v=v2&amp;amp;px=999" role="button" title="dataset for question.PNG" alt="dataset for question.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 5 groups (colvar).&lt;/P&gt;
&lt;P&gt;My question is, how I can summarize the variable 'n' by group, summing from "&amp;gt;=21" to "&amp;gt;=3", so that for last observation here I would have the summary of all the distributed values above it? (e.g. new 'sum' variable for obs=7 would be&amp;nbsp; 393 (9+42+56+80+98+75+33)).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have&amp;nbsp; tried something like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	retain sum1 0;
	set adsl5_2;
		by colvar;
		sum1=sum1 + n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it is processing whole dataset and not by group&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="webart999ARM_0-1668712665765.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77415i9F2983D7D091682B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="webart999ARM_0-1668712665765.png" alt="webart999ARM_0-1668712665765.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for any help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sincerely&lt;/P&gt;
&lt;P&gt;Artur&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 19:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844947#M334045</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2022-11-17T19:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: By group summary of distributed values in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844949#M334047</link>
      <description>&lt;P&gt;Try this. Here, we set sum1 back to zero when we hit a new by-group.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set adsl5_2;
   by colvar;
   if first.colvar then sum1 = 0;
   sum1 + n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 19:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844949#M334047</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T19:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: By group summary of distributed values in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844950#M334048</link>
      <description>&lt;P&gt;You are using the word "summary" and "sum" as if they are interchangeable and mean the same thing. I wouldn't do that, but assuming that is what you intended, then this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by colvar;
    if first.colvar then summary=0;
    summary+n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 19:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844950#M334048</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-17T19:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: By group summary of distributed values in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844951#M334049</link>
      <description>Thank you.</description>
      <pubDate>Thu, 17 Nov 2022 19:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844951#M334049</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2022-11-17T19:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: By group summary of distributed values in the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844955#M334052</link>
      <description>This one works as well, thank you.&lt;BR /&gt;And I agree with your suggestion about "summary" and "sum", indeed, they are different things.</description>
      <pubDate>Thu, 17 Nov 2022 19:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/By-group-summary-of-distributed-values-in-the-variable/m-p/844955#M334052</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2022-11-17T19:32:12Z</dc:date>
    </item>
  </channel>
</rss>

