<?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: Proc SQL Query in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Query/m-p/644710#M78480</link>
    <description>&lt;P&gt;Please stop shouting at the poor SAS interpreter, it hasn't done anything to deserve this.&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    team,
    sum (case
      when team = 'T1' and finish le 3 or team = 'T2' and finish le 5
      then cl1
      else 0
      end
    ) as temp_cl1,
    sum (case
      when team = 'T1' and finish le 3 or team = 'T2' and finish le 5
      then cl2
      else 0
      end
    ) as temp_cl2
  from have
  group by team
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 02 May 2020 13:04:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-02T13:04:47Z</dc:date>
    <item>
      <title>Proc SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Query/m-p/644700#M78478</link>
      <description>&lt;P&gt;May I know how to calculate the sum for team1 with finish le 3 for team1, and finish le 5 for team2 (as stated in below code) for both temp_cl columns?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT ID TEAM $ RANK $ CL1 CL2 FINISH;&lt;BR /&gt;DATALINES;&lt;BR /&gt;120 T1 A1 0 0 1&lt;BR /&gt;121 T1 A2 20 30 1&lt;BR /&gt;122 T1 A2 30 50 2&lt;BR /&gt;123 T1 A2 40 60 3&lt;BR /&gt;124 T1 A2 50 40 4&lt;BR /&gt;125 T1 A2 60 30 5&lt;BR /&gt;220 T2 A1 0 0 1&lt;BR /&gt;221 T2 A2 24 130 1&lt;BR /&gt;222 T2 A2 34 150 2&lt;BR /&gt;223 T2 A2 44 160 3&lt;BR /&gt;224 T2 A2 54 140 4&lt;BR /&gt;225 T2 A2 64 130 5&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE TEST1 AS SELECT *,&lt;BR /&gt;COALESCE((SELECT SUM(CL1) FROM TEST WHERE TEAM=A.TEAM AND FINISH LE 5),CL1)&lt;BR /&gt;AS TEMP_CL1,&lt;BR /&gt;COALESCE((SELECT SUM(CL2) FROM TEST WHERE TEAM=A.TEAM AND FINISH LE 5),CL2)&lt;BR /&gt;AS TEMP_CL2&lt;BR /&gt;FROM TEST A;&lt;BR /&gt;QUIT&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 12:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Query/m-p/644700#M78478</guid>
      <dc:creator>scb</dc:creator>
      <dc:date>2020-05-02T12:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Query/m-p/644708#M78479</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80526"&gt;@scb&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this code meet your expectations?&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table test1 as
	
 	select a.*, b.TEMP_CL1, b.TEMP_CL2
 	from test as a inner join
 		 (select distinct team,
 		 		 sum(CL1) as TEMP_CL1,
 		 		 sum(CL2) as TEMP_CL2
 		 from test
 		 where team="T1" and finish le 2) as b
 	on a.team=b.team
 	
 	union all corr
 	
 	select a.*, b.TEMP_CL1, b.TEMP_CL2
 	from test as a inner join
 		 (select distinct team,
 		 		 sum(CL1) as TEMP_CL1,
 		 		 sum(CL2) as TEMP_CL2
 		 from test
 		 where team="T2" and finish le 5) as b
 	on a.team=b.team;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture d’écran 2020-05-02 à 14.59.13.png" style="width: 362px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38996iD7F92D27F73AA39F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-05-02 à 14.59.13.png" alt="Capture d’écran 2020-05-02 à 14.59.13.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 13:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Query/m-p/644708#M78479</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-02T13:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Query/m-p/644710#M78480</link>
      <description>&lt;P&gt;Please stop shouting at the poor SAS interpreter, it hasn't done anything to deserve this.&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    team,
    sum (case
      when team = 'T1' and finish le 3 or team = 'T2' and finish le 5
      then cl1
      else 0
      end
    ) as temp_cl1,
    sum (case
      when team = 'T1' and finish le 3 or team = 'T2' and finish le 5
      then cl2
      else 0
      end
    ) as temp_cl2
  from have
  group by team
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 May 2020 13:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Query/m-p/644710#M78480</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-02T13:04:47Z</dc:date>
    </item>
  </channel>
</rss>

