Im trying to obtain a summary and provide a total for each variable by rep. The problem im having is that this code still brings back all records, however the average and and totals are correct but it displays the same numeric for each record. Any idea why it wont display 1 row with the totals?
PROC SQL;
create table work.redemptions_summary as
select
a.month_date,
repay_Type as Rep
count(*) as count,
avg (a.i_tv) as Ave_tv,
avg (a.bal_o) as Average_Bal,
avg (b.cii) as cii,
avg (b.deli) as del,
count(*) as red_vol,
sum(bal_out) as red_bal,
sum(case when Rep= 'Cap' then bal_out else 0 end) as cap,
sum(case when Rep= 'Int' then bal_out else 0 end) as int,
sum(case when Rep= 'Mixed' then bal_out else 0 end) as part,
sum(bal_out)as Total_Bal,
case
when remaining_months <= 1 then 'End'
when remaining_months <= 12 then 'OP'
when arr_stage_code ne 'ZZ' then 'Ar'
else 'Rem' end as Red_rea
from
work.red as a
left join work.red_stats as b
on a.anm = b.aco
where
platform = 'um'
and Arr_stage_code not in ('4','5','6')
group by
rep,
month_date;
quit;
I would imagine that its to do with the case statement creating a unique value for each of the rows. You can try putting select distinct to start, and also remove the case statement. You should then get one row per by group.
Just bring case statement under group by with an aggregate function.
You need to aggregate your case statement.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.