turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Percent format question

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-17-2015 08:57 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Elliott

04-17-2015 09:16 AM

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

Maxims of Maximally Efficient SAS Programmers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Elliott

04-17-2015 09:29 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Elliott

04-17-2015 10:00 AM

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 --<-----

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to jakarman

04-17-2015 10:33 AM

Thanks, Jaap! I must have been blind .