Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Breaks in Proc Report

Status
Not open for further replies.

methylparoben

Programmer
Apr 18, 2008
2
US
I am curious if Proc Report can print break statements conditionally. I have a table of values with a dummy variable that is used for grouping. I want a break statement to be executed after each dummy variable grouping EXCEPT the final one. The final group always has only 1 observation and therefore any summary line is redundant. Can anyone help me?

Thank you.
 
You might be able to do this using a "compute after" statement...

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
methylparoben,

Did you ever figure this on out. I have the same need.

Thanks for any help.
 
rwallace2,

The workaround is VERY cumbersome. It involves making a dummy variable for every unique summary line you wish to display. You then override the values of these summary lines to display the data you wish. I can send you some sample code if you like, but my team decided to simply use the default Proc Report routine and delete the redundant lines when we output to excel.

It may or may not be worth the added hassle.



SELF-CONTAINED CODE:

data test1;

do i = 1 to 1000;
random1 = ranuni(1);
random2 = ranuni(2);

score = round((500+(random1*400)),1);
if mod(i,20) = 1 then score = 222;
proxy=score;

var1 = (random2<=.333);
var2 = (random2>=.800);

exception='x';
subtotal='y';
count=1;

output;
end;
run;

proc format;
value score
low-600='low-600'
601-700='601-700'
701-800='701-800'
801-900='801-900'
9997 ='Subtotal'
9998 ='222s'
9999 ='Grand Total'
;
run;

proc sql ;
/* Grand Total Calculations */
select sum(var1) into :var1_gtot
from test1;
select sum(var2) into :var2_gtot
from test1;
select mean(var1) into :var1_pct
from test1;
select mean(var2) into :var2_pct
from test1;
select sum(count) into :totn
from test1;

/* Exception Calculations */
select sum(count) into:ntot_exc
from test1
where score eq 222;
select sum(var1) into :var1_sum_exc
from test1
where score eq 222;
select sum(var2) into :var2_sum_exc
from test1
where score eq 222;
select mean(var1) into :var1_pct_exc
from test1
where score eq 222;
select mean(var2) into :var2_pct_exc
from test1
where score eq 222;

quit;


proc report data=test1;
column exception subtotal score proxy count var1 var1_csum var1=var1_pct var1_cpct var2;

define exception / group noprint;
define subtotal / group noprint;
define score / group noprint format=score.;
define proxy / analysis max format=score.;
define count / analysis n;
define var1 / analysis sum;
define var1_csum / computed;
define var1_pct / analysis mean;
define var1_cpct / computed;

define var2 / analysis sum;

break after exception / summarize;
break after subtotal / summarize;

rbreak after / summarize;

compute before;
var1_sub = var1.sum;
var2_sub = var2.sum;
var1_tot = 0;
endcomp;

compute var1_csum;
var1_tot + var1.sum;
var1_csum = var1_tot;
if not missing(_break_) then var1_csum = .;
endcomp;

compute var1_cpct;
var1_cpct = var1_csum / var1_sub;
endcomp;

compute after subtotal;
proxy.max = 9997;
var1.sum = var1_sub;
var2.sum = var2_sub;
endcomp;

compute after exception;
proxy.max = 9998;
count.n = &ntot_exc;
var1.sum = &var1_sum_exc;
var2.sum = &var2_sum_exc;
var1_pct = &var1_pct_exc;
var2_pct = &var2_pct_exc;
endcomp;

compute after;
proxy.max = 9999;
count.n = &totn;
var1.sum = &var1_gtot;
var2.sum = &var2_gtot;
var1_pct = &var1_pct;
var2_pct = &var2_pct;
endcomp;

where score ne 222;

run;
 
Thanks methylparoben.

I will give it a try.

I did submit my problem to SAS. They said they are working on a fix for a future version.

Take care.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top