BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Palucci
Fluorite | Level 6

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;

 

DATECustomer 1Customer 2
2021-08195
2021-08277
SUM3172
Mean1,586
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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.

Cynthia_sas_0-1635958643451.png

 



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

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

What does your data look like? And what is your desired result?

Palucci
Fluorite | Level 6
At the top, this table is my result that I want to achieve. and the data look the same but without Sum / Median
Ksharp
Super User

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;
Cynthia_sas
SAS Super FREQ

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.

Cynthia_sas_0-1635958643451.png

 



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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1116 views
  • 1 like
  • 5 in conversation