Help using Base SAS procedures

proc report: how to add a computed row?

Reply
Regular Contributor
Regular Contributor
Posts: 156

proc report: how to add a computed row?

Hello!

I have a proc report with group, across and an analysis variable. Furthermore there is a break and an rbreak. All this works well. Now I'd like to add an additional row after each break. Yet I don't want to do this with the line statement but in a way so that there are all individual cells for each column like in a break statement. You can think of this wished-for line like a break statment which however contains any computation that I want and not only a summary.

Here is the code for the part that works:


proc report data=work.mydata;

column mygroupfield1 mygroupfield2 myacrossfield myvalues;

define mygroupfield1 / group;
define mygroupfield2 / group;
define myacrossfield / across;
define myvalues / analysis sum;

break after mygroupfield2 / summarize;
rbreak after / summarize;

run;


The new row which I want to insert should come after the break of mygroupfield2.

Can anybody help?

Best regards,
Eva
SAS Super FREQ
Posts: 8,743

Re: proc report: how to add a computed row?

Hi:
As you have discovered the LINE statement produces one row that spans all the columns in the report.

One method to produce the creation of extra summary lines is shown in this most excellent paper:
http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf
(on pages 7 and 8, in the section entitled "Adding Multiple Summary Rows")

cynthia
SAS Super FREQ
Posts: 8,743

Re: proc report: how to add a computed row?

Hi:
As you have discovered the LINE statement produces one row that spans all the columns in the report.

One method to produce the creation of extra summary lines is shown in this most excellent paper:
http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf
(on pages 7 and 8, in the section entitled "Adding Multiple Summary Rows")

cynthia
Regular Contributor
Regular Contributor
Posts: 156

Re: proc report: how to add a computed row?

Dear Cynthia,

thanx for your great answer. Still there are two things which don't work.

First: the newly computed "summary" line appears before the other break. I'd like to have that after the other break. Changing orders in the column statement however doesn't do the trick as the computed summary line then appears somewhere completely different (after each change of value for the second group variable - mygroupfield2).

Second: doing any computation doesn't work either. It is ignored and the same values as in the other break statement are displayed.

Here is my code:

/* add the helping variable to later display the computed break line */
data work.mydata;

set work.mybasedata;

myhelp = 1;

run;

proc report data=work.mydata;

column mygroupfield1 myhelp mygroupfield2 myacrossfield myvalues;

define mygroupfield1 / group;
define myhelp / group noprint;
define mygroupfield2 / group;
define myacrossfield / across;
define myvalues / analysis sum;

break after mygroupfield1 / summarize;
break after myhelp / summarize;
rbreak after / summarize;

compute after myhelp;
mygroupfield1 = 'percentage';
myvalues = (mysum / mysupersum) * 100;
endcomp;

compute before mygroupfield1;
mysum = myvalues.sum;
endcomp;

compute before;
mysupersum = myvalues.sum;
endcomp;

run;

Usind myvalues.sum in the compute after myhelp doesn't work unfortunately. I get the error
ERROR: The variable type of MYVALUES.SUM is invalid in this context.
ERROR: Illegal reference to the array MYVALUES.SUM.

Best wishes
Eva
Ask a Question
Discussion stats
  • 3 replies
  • 157 views
  • 0 likes
  • 2 in conversation