DATA Step, Macro, Functions and more

How to assign a percent format to a computed variable in proc report

Reply
Contributor
Posts: 23

How to assign a percent format to a computed variable in proc report

[ Edited ]
proc report;
column pct_x;
define pct_x / computed width=6 ' % of X';
compute pct_x / length = 5;
pct_x = (num_x/denom_x)*100;
endcomp;
run; 

 Whenever I try to assign format statement in either define row or compute row I get 0% as result instead of the actual value.

WIth this code I am getting the right percentages but they do not seem to be formatted (eg 27.53, 4.567). I want to keep only two digits after the decimal point and insert a % sign as well if possible (eg 27.53%, 4.56%)

 

Thank you for your help.

Super User
Posts: 24,028

Re: How to assign a percent format to a computed variable in proc format

We can't run your code if you don't provide sample data. 

And it's really bad practice to not have a DATA= in your PROCS.

 

proc report data=have nowd;

 

Super User
Posts: 6,939

Re: How to assign a percent format to a computed variable in proc report

Percent formats are tricky in two respects.

 

First, they expect to see decimal fractions.  So don't multiply by 100.

 

Second, they need a wider width than you would imagine.  Percent formats insert a blank before and after.  So printing 100.00% requires a total of 9 characters.

Ask a Question
Discussion stats
  • 2 replies
  • 66 views
  • 0 likes
  • 3 in conversation