turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- ODS and Base Reporting
- /
- proc report

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-11-2011 09:54 AM

Hi,

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';

else

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

Endcomp;

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;

Endcomp;

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

run;

\

Thanks in Advance

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';

else

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

Endcomp;

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

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

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;

Endcomp;

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

run;

\

Thanks in Advance

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to raveena

05-11-2011 10:25 AM

Hi:

I cannot think of any situation where*varname.sum* would be a character value, as you indicate by '0' in your comparison.

[pre]

if _freq_p.sum='0' then change='100';

[/pre]

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:

[pre]

if _freq_p.sum='Z' then change='100';

[/pre]

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:

[pre]

Compute change / character length=5;

. . . more code . . .

Endcomp;

[/pre]

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.

cynthia

I cannot think of any situation where

[pre]

if _freq_p.sum='0' then change='100';

[/pre]

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:

[pre]

if _freq_p.sum='Z' then change='100';

[/pre]

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:

[pre]

Compute change / character length=5;

. . . more code . . .

Endcomp;

[/pre]

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.

cynthia