This is my first time here, I hope that you will help me. I would like to add SUM / MEANS as a summary using Proc Reports. ?The following code does not help me if there is any possibility
proc report data=customer;
column date customer ,number_sold
define date / group;
define customer / across;
define number_sold/ mean;
define number_sold/ sum;
run;
DATE | Customer 1 | Customer 2 |
2021-08 | 1 | 95 |
2021-08 | 2 | 77 |
SUM | 3 | 172 |
Mean | 1,5 | 86 |
Hi:
You can do what you want to do with PROC REPORT, but it will take some different coding. You are showing your desired results. For CUSTOMER to be used as an across variable, the data has to look different than what you show in your first post. Consider this code and the report it produces. The 19 rows in SASHELP.CLASS are shown with AGE as the GROUP item and with height nested within each value of SEX, which is the ACROSS variable.
If you want to add an extra summary line at the bottom, then you have to do data manipulation like I show in this paper https://support.sas.com/resources/papers/proceedings17/SAS0431-2017.pdf in Example 2, 3, 4 or 5. Probably #5, but without really seeing your actual data, it's hard to guess.
Cynthia
What does your data look like? And what is your desired result?
You can't do it in proc report.
Pre-process data before proc report.
proc sql;
create table report as
select 1 as id, put(date,yymmd7.) as date length=20, stock as customer, sum(close) as numer_sold
from sashelp.stocks
where date<'01jan1987'd
group by calculated date ,stock
union all
select 2,'sum', stock as customer,sum(close) as numer_sold
from sashelp.stocks
where date<'01jan1987'd
group by stock
union all
select 3,'mean', stock as customer,mean(close) as numer_sold
from sashelp.stocks
where date<'01jan1987'd
group by stock
;
quit;
proc report data=report nowd;
column id date numer_sold,customer;
define id/group noprint;
define date/group;
define customer/across ' ';
define numer_sold/analysis sum ' ';
run;
I moved this to the "Base Reporting" community. Maybe @Cynthia_sas can chime in with a clever trick.
Hi:
You can do what you want to do with PROC REPORT, but it will take some different coding. You are showing your desired results. For CUSTOMER to be used as an across variable, the data has to look different than what you show in your first post. Consider this code and the report it produces. The 19 rows in SASHELP.CLASS are shown with AGE as the GROUP item and with height nested within each value of SEX, which is the ACROSS variable.
If you want to add an extra summary line at the bottom, then you have to do data manipulation like I show in this paper https://support.sas.com/resources/papers/proceedings17/SAS0431-2017.pdf in Example 2, 3, 4 or 5. Probably #5, but without really seeing your actual data, it's hard to guess.
Cynthia
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.