01-29-2017 07:38 PM
rounded output example
format pct percent4.;
I want to format the percent as such however its not formatting correctly
01-29-2017 07:46 PM
This seems to work for me HAVE Up to 40 obs WORK.HAVE total obs=3 Obs PCT2 1 0.101 2 0.201 3 0.301 WANT Obs PCT 1 10% 2 20% 3 30% SOLUTION * create some data; data have; do pct2=.101 to .301 by .1; output; end; run;quit; * format new variable; data want; set have; format pct percent.; pct=pct2; drop pct2; run; * print with format; proc print data=want; run;quit;
01-29-2017 07:57 PM - edited 01-29-2017 07:58 PM
This response points out one of the issues with the percent format. It expects to see values between 0 and 1, not between 0 and 100. So you need to adjust your values accordingly. Values greater than 1 are permitted, so 1.5 prints as 150%.
Another issue is that the percent format adds a leading and a trailing blank. That happens because it prints negative numbers in parentheses rather than using a negative sign. So you need to allow enough room in the format width for those characters. If that is less than ideal, you can switch to the PERCENTN format instead of the PERCENT format. No trailing blank is needed, and negative numbers print with a negative sign.
01-30-2017 12:26 AM
Another option is to create your own format that handles whole numbers.
This is a common question since both PROC TABULATE/FREQ report percents between 0 and 100.
The Code tab has the code for a custom format