<?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 data in with unique identifier in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680363#M205594</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
&amp;nbsp; &amp;nbsp;class ID;
&amp;nbsp; &amp;nbsp;var a;
&amp;nbsp; &amp;nbsp;output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 31 Aug 2020 04:29:52 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-08-31T04:29:52Z</dc:date>
    <item>
      <title>Sum data in with unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680362#M205593</link>
      <description>&lt;P&gt;Hello Sir/Madam,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this longitudinal data that I wish to sum by each id, for example the data is;&lt;/P&gt;
&lt;P&gt;Data DD;&lt;/P&gt;
&lt;P&gt;Input id A;&lt;/P&gt;
&lt;P&gt;Cards;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a new data by summing A by id such that the new data will be;&lt;/P&gt;
&lt;P&gt;id&amp;nbsp; &amp;nbsp;sum_A&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;11(2+5+3+1)&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;DA&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 04:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680362#M205593</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2020-08-31T04:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sum data in with unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680363#M205594</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
&amp;nbsp; &amp;nbsp;class ID;
&amp;nbsp; &amp;nbsp;var a;
&amp;nbsp; &amp;nbsp;output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Aug 2020 04:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680363#M205594</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-31T04:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sum data in with unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680365#M205596</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dd;
Input id A;
cards;
1 2
1 5
1 3
1 1
2 2
2 1
2 3
;

proc summary data=dd nway;
   class id;
   var A;
   output out=want(drop=_:) sum(A)=sum_A;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Aug 2020 05:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680365#M205596</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-08-31T05:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sum data in with unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680411#M205623</link>
      <description>&lt;P&gt;Always more than one way to do things in SAS. Apart from PROC SUMMARY, you can use a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
    set dd;
    by id;
    sum_A=sum(sum_A,A);
    end;
  drop A;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as select
    id,
    sum(A) as sum_A
    from dd
    group by id
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first solution requires the data to be sorted, but may be faster if it already is sorted. But not necessarily; if SAS knows that the data is sorted (you used a PROC SORT or an SQL ORDER BY statement to create it), the two are probably equivalent. The same goes for PROC SUMMARY, where you can use BY ID instead of CLASS ID if the data is already sorted, which again may perform better if does not know that the data is sorted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally, PROC SQL will deliver the data in the GROUP BY order, but this is not guaranteed behavior, so you may want to add an ORDER BY ID at the end of the SQL query, then it's explicit.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 11:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680411#M205623</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-08-31T11:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sum data in with unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680425#M205631</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 12:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680425#M205631</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2020-08-31T12:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sum data in with unique identifier</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680426#M205632</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;
&lt;P&gt;FA&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 12:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-data-in-with-unique-identifier/m-p/680426#M205632</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2020-08-31T12:56:30Z</dc:date>
    </item>
  </channel>
</rss>

