BookmarkSubscribeRSS Feed
div44
Calcite | Level 5
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.

2 REPLIES 2
Reeza
Super User

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;

 

Astounding
PROC Star

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 789 views
  • 0 likes
  • 3 in conversation