<?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: summarizing data by proc sql in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505601#M1189</link>
    <description>Is there a variable named person_id in the table? From your code you referred to it that way, but your example data shows a variable named ID? And do the variables have the same type.</description>
    <pubDate>Thu, 18 Oct 2018 15:06:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-10-18T15:06:01Z</dc:date>
    <item>
      <title>summarizing data by proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505385#M1152</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have
input year id v1 v2 v3;
cards;
1 1 . 1 20
1 1 . 1 30
1 1 . 1 10
2 1 . 1 10
3 1 . 1 10
3 1 . 1 20
1 2 . 1 20
1 2 . 2 30
2 2 . 1 20
2 2 . 1 20
;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;From this data,&lt;/P&gt;&lt;P&gt;I want to summarize the number by id and year. What I want is...&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input year id v1_sum v2_sum v3_sum;
cards;
1 1 . 3 60
2 1 . 1 10
3 1 . 2 30
1 2 . 3 50 
2 2 . 2 40
3 2 . . .
; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The code I tried is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table sum_diag as&lt;BR /&gt;select person_id, year,&lt;BR /&gt;from diagnos&lt;BR /&gt;group by year&lt;BR /&gt;order by person_id, year; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't get the result by year. There were multiple observations&amp;nbsp; per&amp;nbsp;year for several rows. What should I do to get sum by year within a subject?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 22:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505385#M1152</guid>
      <dc:creator>asinusdk</dc:creator>
      <dc:date>2018-10-17T22:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: summarizing data by proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505386#M1153</link>
      <description>&lt;P&gt;Any reason to not use a summary proc designed for analysis?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either way, your code doesn't show any attempt at summarization, did you remove that portion before posting?&lt;/P&gt;
&lt;P&gt;Otherwise, adding in your summary stats is all you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table sum_diag as
select person_id, year, sum(v1) as sum_v1, sum(v2) as sum_v2
from diagnos
group by year
order by person_id, year; quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 22:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505386#M1153</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-17T22:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: summarizing data by proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505387#M1154</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table sum_diag as
select id, year, sum(v1) as v1_sum,sum(v2) as  v2_sum ,sum(v3) as v3_sum
from diagnos
group by id,year
order by id, year; 
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 22:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505387#M1154</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-17T22:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: summarizing data by proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505420#M1164</link>
      <description>&lt;P&gt;You can&amp;nbsp;include&amp;nbsp;the combinations of year and id that do not occur in your data wit a cross join (cartesian product) and a left join:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.year, b.id,
    sum(v1) as sumV1, sum(v2) as sumV2, sum(v3) as sumV3
from 
    (select unique year from have) as a cross join
    (select unique id from have) as b left join
    have as c on a.year=c.year and b.id=c.id
group by a.year, b.id
order by id, year;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 03:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505420#M1164</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-10-18T03:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: summarizing data by proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505586#M1186</link>
      <description>&lt;P&gt;I actually tried this code, but the result showed the sum of all v1 frequency from all subjects and all years.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 14:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505586#M1186</guid>
      <dc:creator>asinusdk</dc:creator>
      <dc:date>2018-10-18T14:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: summarizing data by proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505600#M1188</link>
      <description>&lt;P&gt;ERROR: Column person_id could not be found in the table/view identified with the correlation&lt;BR /&gt;name b.&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much...But these errors came up...&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 14:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505600#M1188</guid>
      <dc:creator>asinusdk</dc:creator>
      <dc:date>2018-10-18T14:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: summarizing data by proc sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505601#M1189</link>
      <description>Is there a variable named person_id in the table? From your code you referred to it that way, but your example data shows a variable named ID? And do the variables have the same type.</description>
      <pubDate>Thu, 18 Oct 2018 15:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/summarizing-data-by-proc-sql/m-p/505601#M1189</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-18T15:06:01Z</dc:date>
    </item>
  </channel>
</rss>

