data app_summary02;
set app_summary2;
pct2=round(pct);
run;
rounded output example
100
50
70
data app_summary2;
set app_summary02;
format pct percent4.;
pct=pct2;
drop pct2;
run;
I want to format the percent as such however its not formatting correctly
Desired result
100%
50%
70%
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;
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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.