Solved
Contributor
Posts: 66

# Proc report- 'Compute' computed missing values!

I am trying to divide one variable by another one and want to express the result as percentage.

Here is my attempt, that does not work!

Here is the output:

Raghu.

Accepted Solutions
Solution
‎03-06-2013 11:51 PM
Frequent Contributor
Posts: 81

## Re: Proc report- 'Compute' computed missing values!

Hi RNMishra,

Please find below the solution and its output:-

==============================================

data have;

input xx \$ yy zz @@;

datalines;

aa 1000 236

bb 678 231

cc 678 231

dd 500 59

ee 890 34

;

run;

proc report data=have;

columns xx yy zz newvar;

define xx/'total';

define zz/'obtained';

define newvar/computed format=percent8.2 'Percentage';

compute newvar;

newvar=zz.sum/yy.sum;

endcomp;

run;

=======================================================

Output:-

============================================================

Percenta

total            yy   obtained        ge

aa             1000        236   23.60%

bb              678        231   34.07%

cc              678        231   34.07%

dd              500         59   11.80%

ee              890         34    3.82%

===========================================================

/Daman

All Replies
Super User
Posts: 23,700

## Re: Proc report- 'Compute' computed missing values!

I'm not 100% sure about this, but I think you need to specify a statistic to be able to do what you want. This doesn't matter since you're doing row by row calculations.

See this reference.

http://www2.sas.com/proceedings/forum2008/031-2008.pdf

data have;

input xx \$ yy zz;

cards;

aa 1000 236

bb 678 345

cc 678 231

dd 500 59

ee 800 39

;

proc report data=have nowd;

columns xx yy zz newvar;

define xx/ 'sample';

define yy/ 'YY' analysis max;

define zz/ 'ZZ' analysis max;

define newvar/computed format=percent8.2 'New Var';

compute newvar;

newvar=zz.max/yy.max;

endcomp;

run;

Super User
Posts: 8,089

## Re: Proc report- 'Compute' computed missing values!

Or just define ZZ and YY as display variables.  Then you can reference ZZ and YY in the compute block.

Solution
‎03-06-2013 11:51 PM
Frequent Contributor
Posts: 81

## Re: Proc report- 'Compute' computed missing values!

Hi RNMishra,

Please find below the solution and its output:-

==============================================

data have;

input xx \$ yy zz @@;

datalines;

aa 1000 236

bb 678 231

cc 678 231

dd 500 59

ee 890 34

;

run;

proc report data=have;

columns xx yy zz newvar;

define xx/'total';

define zz/'obtained';

define newvar/computed format=percent8.2 'Percentage';

compute newvar;

newvar=zz.sum/yy.sum;

endcomp;

run;

=======================================================

Output:-

============================================================

Percenta

total            yy   obtained        ge

aa             1000        236   23.60%

bb              678        231   34.07%

cc              678        231   34.07%

dd              500         59   11.80%

ee              890         34    3.82%

===========================================================

/Daman

🔒 This topic is solved and locked.