## Percent format question

Frequent Contributor
Posts: 94

# Percent format question

I am using a percent7.4 format for a calculation and specifically looking for any percentage greater than 101%.  The problem is any percentage greater than 100 is not showing any decimal places.  My users are questioning the value as the requements state GT 101%, but I am not able to show the decimal places that prove the percentage is actually greater than 101%.  How do I solve for that?  that is part one, that piece is on mainframe.

I then move the data file to a unix server where I have a program that pulls in the data and uses ods to create a report in excel.  I currently am reading in that percentage as character 6., and outputting  as tagattr='format:##00.0%'.  Is that tagattr correct for the output I am looking for?

thanks,

Cindy

Super User
Posts: 10,280

## Re: Percent format question

Keep in mind that with a percent7.4 format, you run out of space quickly. SAS obviously needs space for more characters than are displayed.

To display % values <= 1 with 4 decimals, use percent11.4.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Posts: 3,167

## Re: Percent format question

This one bothers me as well. In SAS Doc, Percentw.d, w is the total width of the output, d is the digits after decimal point.

So if we have 1.234567, the width should be 7+1(decimal point)+1(%) =9, therefore Percent9.4 should be sufficient to show:  123.4567%. However, we will need Percent11.4 to show the whole number without rounding.

data _null_;

a=1.234567;

b=a;

c=a;

format a percent9.4;

put a=;

format b percent10.4;

put b=;

format c percent11.4;

put c=;

run;

Log shows:

a=123.46%

b=123.457%

c=123.4567%

The reason, my guess, is that this format needs to reserver 2 digits for negative number, which takes length of 2 by denoting as (). see below:

23 data _null_;

24 a=-1.234567;

25 b=a;

26 c=a;

27 format a percent9.4;

28 put a=;

29 format b percent10.4;

30 put b=;

31 format c percent11.4;

32 put c=;

33 run;

a=(123.46%)

b=(123.457%)

c=(123.4567%)

Therefore for your problem, first multiply the number by 100, then decide the digits after the decimal point you want to keep as 'd', then use the formula above and plus 2  as 'w'.

Haikuo

Posts: 3,215

## Re: Percent format question

SAS(R) 9.4 Formats and Informats: Reference   "The width of the output field must account for the percent sign (% ) and parentheses for negative numbers, whether the number is negative or positive."

---->-- ja karman --<-----
Posts: 3,167

## Re: Percent format question

Thanks, Jaap! I must have been blind .

Discussion stats
• 4 replies
• 373 views
• 0 likes
• 4 in conversation