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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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