Proc Report Across Computation

Accepted Solution Solved
Reply
Senior User
Posts: 1
Accepted Solution

Proc Report Across Computation

Hi all,

 

I'm a fairly new SAS programmer and haven't used proc report much yet, but I need to produce a graduation rate table and I believe proc report is my best way to display the result.  I'm having trouble getting the compuations to be correct.

 

I cannot share my data set since it has senstitive information.  My code and output are below.  What I notice is that it fails to compute once a zero is present.

 

I would be grateful for any advice or direction you all can provide!

 

2008 cohort.PNG

 

Title "2008 Cohort";
proc report data = gradcombine1;
where cohort = "2008";
column acad_plan n cbm009year, (n cum);
label acad_plan = "Plan"
	  cbm009year = "Year"
	  ;
define acad_plan / group;
define cbm009year / across;
define n / "#";
define cum / computed "Cumulative %" f=percent8.2;


compute cum;
      /* Calculate cumulative percent */
	_c4_ = _c3_ / _c2_; 
	_c6_ = (_c5_ + _c3_) / _c2_;
	_c8_ = (_c7_ + _c5_ + _c3_) / _c2_;
	_c10_ = (_c9_ + _c7_ + _c5_ + _c3_) / _c2_;
   endcomp;
run;

Accepted Solutions
Solution
‎06-22-2017 03:25 PM
SAS Super FREQ
Posts: 8,819

Re: Proc Report Across Computation

Hi:

  Even if you cannot share your data, you can alter it or fake it like this:

data cohort;
  infile datalines;
  input person $ cohort $ acad_plan $  cbm009year;
datalines;
Person01 2008   AAAA         2009
Person02 2008   AAAA         2009
Person03 2008   AAAA         2009
Person04 2008   AAAA         2009
Person05 2008   AAAA         2009
Person06 2008   AAAA         2009
Person07 2008   AAAA         2009
Person08 2008   AAAA         2009
Person09 2008   AAAA         2009
Person10 2008   AAAA         2010
Person11 2008   AAAA         2010
Person12 2008   AAAA         2010
Person13 2008   AAAA         2010
Person14 2008   AAAA         2013
Person15 2008   AAAA         2014
Person16 2008   BBBB         2009
Person17 2008   BBBB         2010
Person18 2008   BBBB         2010
Person19 2008   CCCC         2010
Person20 2008   CCCC         2010
Person21 2008   CCCC         2010
Person22 2008   CCCC         2010
Person23 2008   CCCC         2010
Person24 2008   CCCC         2010
Person25 2008   CCCC         2010
Person26 2008   CCCC         2010
Person27 2008   CCCC         2010
Person28 2008   CCCC         2010
Person29 2008   CCCC         2010
Person30 2008   CCCC         2010
Person31 2008   CCCC         2010
Person32 2008   DDDD         2009
;
run;

and then your code can be tested easily. Is it everything? No, but is it enough to illustrate your issue, yes.

 

change_to_sum_function.png

 

  As you can see, if you switch to the SUM function for the expression to calculate the cumulative percent, then the value gets calculated correctly and then, the missing=0 option shows 0 for the other cells.

 

cynthia

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,819

Re: Proc Report Across Computation

Hi:
Are you getting any error messages in the log? Is it possible for you to make some "fake" data or use one of the SASHELP datasets to illustrate your example???

Are you numbers actually 0 in those cells or are they missing. When you use missing values in arithmetic, the result is always missing, so
. / 0 or ./13 would not work correctly and if you have the option of missing=0, then you would be seeing 0 in the cells.

cynthia
Solution
‎06-22-2017 03:25 PM
SAS Super FREQ
Posts: 8,819

Re: Proc Report Across Computation

Hi:

  Even if you cannot share your data, you can alter it or fake it like this:

data cohort;
  infile datalines;
  input person $ cohort $ acad_plan $  cbm009year;
datalines;
Person01 2008   AAAA         2009
Person02 2008   AAAA         2009
Person03 2008   AAAA         2009
Person04 2008   AAAA         2009
Person05 2008   AAAA         2009
Person06 2008   AAAA         2009
Person07 2008   AAAA         2009
Person08 2008   AAAA         2009
Person09 2008   AAAA         2009
Person10 2008   AAAA         2010
Person11 2008   AAAA         2010
Person12 2008   AAAA         2010
Person13 2008   AAAA         2010
Person14 2008   AAAA         2013
Person15 2008   AAAA         2014
Person16 2008   BBBB         2009
Person17 2008   BBBB         2010
Person18 2008   BBBB         2010
Person19 2008   CCCC         2010
Person20 2008   CCCC         2010
Person21 2008   CCCC         2010
Person22 2008   CCCC         2010
Person23 2008   CCCC         2010
Person24 2008   CCCC         2010
Person25 2008   CCCC         2010
Person26 2008   CCCC         2010
Person27 2008   CCCC         2010
Person28 2008   CCCC         2010
Person29 2008   CCCC         2010
Person30 2008   CCCC         2010
Person31 2008   CCCC         2010
Person32 2008   DDDD         2009
;
run;

and then your code can be tested easily. Is it everything? No, but is it enough to illustrate your issue, yes.

 

change_to_sum_function.png

 

  As you can see, if you switch to the SUM function for the expression to calculate the cumulative percent, then the value gets calculated correctly and then, the missing=0 option shows 0 for the other cells.

 

cynthia

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 110 views
  • 0 likes
  • 2 in conversation