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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1210 views
  • 0 likes
  • 3 in conversation