Hello
I want to calculate aggregation simple statistics to different groups.
Is there a shorter code that can produce same results?
Maybe via proc format?
proc sql;
create table Want as
select Type,
count(*) as nr_rows format=comma28.,
sum(MSRP) as SUM_MSRP format=comma28.,
sum(Invoice) as SUM_Invoice format=comma28.
from sashelp.cars
group by Type
union all
select 'SUV+Sports' as Type,
count(*) as nr_rows format=comma28.,
sum(MSRP) as SUM_MSRP format=comma28.,
sum(Invoice) as SUM_Invoice format=comma28.
from sashelp.cars
where Type in ('SUV','Sports')
union all
select 'SUV+Hybrid' as Type,
count(*) as nr_rows format=comma28.,
sum(MSRP) as SUM_MSRP format=comma28.,
sum(Invoice) as SUM_Invoice format=comma28.
from sashelp.cars
where Type in ('SUV','Hybrid')
union all
select 'Hybrid+SUV+Sedan+Sports' as Type,
count(*) as nr_rows format=comma28.,
sum(MSRP) as SUM_MSRP format=comma28.,
sum(Invoice) as SUM_Invoice format=comma28.
from sashelp.cars
where Type in ('Hybrid','SUV','Sedan','Sports')
union all
select ' Truck+Wagon' as Type,
count(*) as nr_rows format=comma28.,
sum(MSRP) as SUM_MSRP format=comma28.,
sum(Invoice) as SUM_Invoice format=comma28.
from sashelp.cars
where Type in ('Truck','Wagon')
union all
select 'ALL' as Type,
count(*) as nr_rows format=comma28.,
sum(MSRP) as SUM_MSRP format=comma28.,
sum(Invoice) as SUM_Invoice format=comma28.
from sashelp.cars
;
quit;
... View more