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?
DATA TEST;
INPUT ID TEAM $ RANK $ CL1 CL2 FINISH;
DATALINES;
120 T1 A1 0 0 1
121 T1 A2 20 30 1
122 T1 A2 30 50 2
123 T1 A2 40 60 3
124 T1 A2 50 40 4
125 T1 A2 60 30 5
220 T2 A1 0 0 1
221 T2 A2 24 130 1
222 T2 A2 34 150 2
223 T2 A2 44 160 3
224 T2 A2 54 140 4
225 T2 A2 64 130 5
;
RUN;
PROC SQL;
CREATE TABLE TEST1 AS SELECT *,
COALESCE((SELECT SUM(CL1) FROM TEST WHERE TEAM=A.TEAM AND FINISH LE 5),CL1)
AS TEMP_CL1,
COALESCE((SELECT SUM(CL2) FROM TEST WHERE TEAM=A.TEAM AND FINISH LE 5),CL2)
AS TEMP_CL2
FROM TEST A;
QUIT
Hi @scb
Does this code meet your expectations?
Best,
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;
Please stop shouting at the poor SAS interpreter, it hasn't done anything to deserve this.
Try this:
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.