The SAS Output Delivery System and reporting techniques

proc report

Frequent Contributor
Posts: 90

proc report


Currently I need to calculate the change to the report by using a current count and previous count. My concern is if the prior count is ‘0’ then we can’t divide it, in that case I would like to give a condition if prior count is zero then the change should be appear as ‘100’ in the report.
I applied condition to the code as below,

Compute change;
if _freq_p.sum='0' then change='100';
change=(_freq_.sum -_freq_p.sum)/_freq_p.sum;

But I am not getting any result, what am looking for..

Please let me know the mistakes that I have done ..

Original code
Proc report data=rpt1_compare ls=256 headline headskip split='*' nowd;
Column _freq_ _freq_p change change5;

Define _freq_/sum "CURRENT COUNT &date" width=20format=comma10. Spacing=1;
Define _freq_p/sum "PRIOR COUNT &date_p" width=20format=comma10. Spacing=1;
Define change/computed 'CHANGE %' width=12 format=percent8.2 spacing=1;

Compute change;
Change= (_freq_.sum -_freq_p.sum)/_freq_p.sum;

Define change5/display 'SIGNIFICANT CHANGE >= 5%' width=20 format=$1. Spacing=1;

Thanks in Advance
Posts: 9,368

Re: proc report

I cannot think of any situation where varname.sum would be a character value, as you indicate by '0' in your comparison.
if _freq_p.sum='0' then change='100';

I suspect that your IF test is failing. _FREQ_P should be a numeric, analysis variable if you are getting a SUM statistic for it. Therefore, there is a difference between 0 (the number) and '0' (a text character that happens to be 0). You might as well code:
if _freq_p.sum='Z' then change='100';

Also, if you expect CHANGE to be a numeric variable, then I would expect the change='100' to be causing some automatic conversion messages. If you want CHANGE to be a character variable, then you would have to alter your COMPUTE block to:
Compute change / character length=5;
. . . more code . . .

The DIVIDE function allows you to divide and if the denominator is 0, the DIVIDE function was invented so you would not get the divide by zero error messages.

I suspect that just a little more cleanup will have your program working.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation