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

Hi All,

 

I have 4 groups in my data and I need to summarize based on each column but no repetition of rows. Data looks like this 

 

ZoneRegionZH_AbbreviationRH_AbbreviationExpense_In_Thousands
WesternMaharashtraMHRahul100
WesternMaharashtraMHAjay600
WesternMaharashtraMHAjay200
WesternMaharashtraNGPRahul400
WesternMaharashtraNGPPankaj450
WesternGujaratAMAshok600
WesternGujaratAMAjay400
WesternGujaratGKPankaj300
EasternBengalAMPavan300
EasternBengalAMRajesh400
EasternTripuraGKRohan300

 

And I need output like below 

 

 

ZoneRegionZH_AbbreviationRH_AbbreviationExpense_In_Thousands
WesternMaharashtraMHRahul100
   Total for Rahul100
   Ajay800
   Total for Ajay800
  Total for MH 900
  NGPRahul400
   Total for Rahul400
   Pankaj450
   Total for Pankaj450
  Total for NGP 850
 Total for Maharashtra  1750
Total for Western  1750
EasternBengalAMPavan300
   Total for Pavan300
   Rajesh400
   Total for Rajesh400
  Total for AM 700
 TripuraGKRohan300
   Total for Rohan300
  Total for GK 300
 Total for Tripura 300
Total for Eastern  300
Grand Total   2050

 

 

I tried with the Proc report and Group by on 4 columns but it results in repetition of cell values. Is this doable ? Any help is really appreciated.

 

Thanks in advance 

Swapnil

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

What happened to Gujarat and AM under Western? What order are the rows supposed to be in? Normally the G in Gujarat would sort before the M in Maharashtra. And, Ajay would sort before Rahul. Just curious because what you show here seems different than what you would get.
The break variable information will be repeated unless you use SUPPRESS on the Break statement. However, if you want to customize the text at the break, you'll need a COMPUTE block.

 

  But I wouldn't bother with using SUPPRESS, since you need the values at the break in order to customize the BREAK line as shown below for HTML output:

can_blank_cells_compute.png

 

  Basically a COMPUTE block for an AFTER location can "touch" all the other cells on the row, so in the COMPUTE blocks below, after I customize the main cell for the COMPUTE block, I blank out the other cells on the row:

final_report_blanks.png

 

  That did require a LENGTH statement when the variables were created so that the cells would be wide enough for the customized text:

with_length.png

 

I added order=data to the PROC REPORT DEFINE statements to keep the report in the same order as the original data. Otherwise everything would be in alpha order.


Cynthia

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

Absolutely doable in PROC REPORT. Define ZONE, REGION, ZH_Abbreviation, RH_Abbreviation as GROUP columns, and Expense_In_Thousands as an ANALYSIS column.

 

Then add BREAK AFTER <Varname> / SUMMARIZE statements for ZONE, REGION, ZH_Abbreviation, RH_Abbreviation.

 

Lastly add a RBREAK AFTER / SUMMARIZE statement.

Swapnil_21
Obsidian | Level 7

@SASKiwi  I have tried that way. However, result is not as per our expectations. It shows repeated values on the groups.

 

Proc report data=have;

column zone Region ZH_Abbreviation RH_Abbreviation Expense_in_Thousands;

define Zone / Group "Zone"

define ZH_Abbreviation / Group "ZH Abbreviaton";

define RH_Abbreviation / Group "RH Abbreviation";

define Expense_In_Thousands/ Analysis;

break after Zone / summarize;

break after Region / summarize;

break after ZH_Abbreviation / summarize;

break after RH_Abbreviation / summarize;

RBREAK AFTER/ Summarize;

Run;

 

 

It produces multiple rows per group. However, I want  only first value of the member and rest to be blank.

Cynthia_sas
SAS Super FREQ

What happened to Gujarat and AM under Western? What order are the rows supposed to be in? Normally the G in Gujarat would sort before the M in Maharashtra. And, Ajay would sort before Rahul. Just curious because what you show here seems different than what you would get.
The break variable information will be repeated unless you use SUPPRESS on the Break statement. However, if you want to customize the text at the break, you'll need a COMPUTE block.

 

  But I wouldn't bother with using SUPPRESS, since you need the values at the break in order to customize the BREAK line as shown below for HTML output:

can_blank_cells_compute.png

 

  Basically a COMPUTE block for an AFTER location can "touch" all the other cells on the row, so in the COMPUTE blocks below, after I customize the main cell for the COMPUTE block, I blank out the other cells on the row:

final_report_blanks.png

 

  That did require a LENGTH statement when the variables were created so that the cells would be wide enough for the customized text:

with_length.png

 

I added order=data to the PROC REPORT DEFINE statements to keep the report in the same order as the original data. Otherwise everything would be in alpha order.


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
  • 3 replies
  • 2135 views
  • 2 likes
  • 3 in conversation