Help using Base SAS procedures

format perecnt: erase parentheses for negative values

Reply
Regular Contributor
Regular Contributor
Posts: 156

format perecnt: erase parentheses for negative values

Dear all,

when using the percent format sas displays negatives values like this: (0.05%)
Instead I would like to have -0.05%.
Does anybody know how to do this?

Best regards
Eva
Frequent Contributor
Frequent Contributor
Posts: 76

Re: format perecnt: erase parentheses for negative values

Use the percentnw.d format.

For example

x = -0.313 ;
format x percentn8.2;

results in -31.3%.

You must make sure the w.d is wide enough to include the negative sign and the percent.

See base documentation for further explanation

Linda
Regular Contributor
Regular Contributor
Posts: 156

Re: format perecnt: erase parentheses for negative values

Dear Linda,

unfortunately we still user SAS 9.1 and percentn is only available at SAS 9.2
Do you know how to to it wth sas 9.1 ?

Best regards
Eva
Super Contributor
Posts: 291

Re: format perecnt: erase parentheses for negative values

Eva;

You could multipy by 100 to get the percent value. You could then concatenate a % symbol to the percent value or indicate that the column/row of numbers is expressed in percent. The latter is preferred if there is a column or row of numbers. To have the % symbol beside each number is distracting and clutters the display, aka, poor data visualization practice.

hth,
Bill
Frequent Contributor
Frequent Contributor
Posts: 76

Re: format perecnt: erase parentheses for negative values

I'm using 9.1.3 and I tested the percentnw.d format. It seemed to work. However, I did have to widen the format to 8.2.

My other thought would be to use a picture format in proc format to define the format as follows.

proc format;
picture negpct low - < 0 = '000.00%' (prefix="-" )
0 - high = '000.00%' ;
run;

data test;
length x 8;
format y negpct.;
x = .031;y=x*100;output;
x = -0.435;y=x*100; output;

run;
Frequent Contributor
Frequent Contributor
Posts: 76

Re: format perecnt: erase parentheses for negative values

Sorry not all went through....

proc format;
picture negpct low - < 0 = '000.00%' (prefix="-" )
0 - high = '000.00%' ;
run;

data test;
length x 8;
format y negpct.;
x = .031;y=x*100;output;
x = -0.435;y=x*100; output;

run;
Frequent Contributor
Frequent Contributor
Posts: 76

Re: format perecnt: erase parentheses for negative values

Good grief Not sure how to get this to post....

'000.00%' (prefix = "-")
0 - high = '000.00%' ;
run;

You will have to multiply the number by 100 your self.

Hope this posts correctly now.

Linda




Message was edited by: LAP

Message was edited by: LAP Message was edited by: LAP
Super Contributor
Super Contributor
Posts: 3,174

Re: format perecnt: erase parentheses for negative values

The topic is discussed here - found on the SAS support website with a SEARCH.

Scott Barry
SBBWorks, Inc.

Don't Be a SAS® Dinosaur: Modernizing Programs with Base SAS 9.2 Enhancements
Warren Repole Jr., SAS Institute Inc.- Figure 13a.
http://support.sas.com/resources/papers/proceedings09/143-2009.pdf
SAS Super FREQ
Posts: 8,744

Re: format perecnt: erase parentheses for negative values

Hi:
When you need to post code to the forum and particularly when your code has < or > symbols or you need the indenting to line up, this posting tells how to make that happen using special formatting commands:

http://support.sas.com/forums/thread.jspa?messageID=27609毙

cynthia
Regular Contributor
Regular Contributor
Posts: 156

Re: format perecnt: erase parentheses for negative values

Dear Linda,

many thanks for your post. It works!
Here's your example - I hope it posts correctly:

[pre]
proc format;
picture negpct low - < 0 = '000.00%' (prefix="-" )
0 - high = '000.00%' ;
run;

data test;
length x 8;
format y negpct.;
x = .031;y=x*100;output;
x = -0.435;y=x*100; output;

run;
[/pre]

Best wishes
Eva
Frequent Contributor
Posts: 120

Re: format perecnt: erase parentheses for negative values

Hi!
If intend to use picture format you do not have to multiply the value it is in the picture.....

proc format;
picture negpct
0 - high = '009.999%' (mult=100000)
low - 0 = '009.999%' (prefix='-' mult=100000)
;
run;
Ask a Question
Discussion stats
  • 10 replies
  • 1292 views
  • 2 likes
  • 6 in conversation