Hello
I have numeric values that present percentage.
I want to add % symbol to each of the numbers.
For example: instead of 2.14 we will see (format) 2.14%
I know to it by divide each number by 100 and then format it with percent9.2
My question is if there is another way to do it without divide by 100
Data a;
input x1 x2 x3;
cards;
2.14 2.46 3.3
19.83 18.57 18.06
35.43 33.39 36.44
3.66 2.73 4.68
;
run;
Sure.
The question is how to perform format such that the values will be displayed with %
for example: value 2.14 will be displayed as 2.14%
@Ronein wrote:
Sure.
The question is how to perform format such that the values will be displayed with %
for example: value 2.14 will be displayed as 2.14%
You already have the most convenient method in your initial post: divide by 100 and apply percent-format. A bit more arcane: you could define a picture format adding % and apply that.
I want also to learn the way with proc format picture .
As you can see in data set c the values are not displayed as I want.
I cannot see the % symbol and for example instead of see 2.14% I see 2
Data a;
input x1 x2 x3;
cards;
2.14 2.46 3.3
19.83 18.57 18.06
35.43 33.39 36.44
3.66 2.73 4.68
;
run;
proc format;
picture mypct (round) low-high='009.99%';
run;
data c;
set a;
format x1 x2 x3 mypct.;
run;
@Ronein wrote:
I want also to learn the way with proc format picture .
As you can see in data set c the values are not displayed as I want.
I cannot see the % symbol and for example instead of see 2.14% I see 2
Data a; input x1 x2 x3; cards; 2.14 2.46 3.3 19.83 18.57 18.06 35.43 33.39 36.44 3.66 2.73 4.68 ; run; proc format; picture mypct (round) low-high='009.99%'; run; data c; set a; format x1 x2 x3 mypct.; run;
What do you think the ROUND above does? Why did you include it if you want two decimal places?
It rounds the value to nearest integer so the result is what you told it to provide.
You would likely be better off using a ROUND function on the value to set the desired decimals and then apply a format without the round as part of the definition.
Or use a real percent value and the Percent format.
Because that's code from the SAS website, not from the OP and s/he likely doesn't understand it yet.
@ballardw wrote:
What do you think the ROUND above does? Why did you include it if you want two decimal places?
It rounds the value to nearest integer so the result is what you told it to provide.
You would likely be better off using a ROUND function on the value to set the desired decimals and then apply a format without the round as part of the definition.
Or use a real percent value and the Percent format.
"My question is if there is another way to do it without divide by 100"
If you're in the mood for unnecessary work, create a custom picture format.
Keep in mind that it makes sense to store 1 percent as 0.01, as it enables you to do percent calculations without the (otherwise needed) division by 100.
I just don't understand why the format that I created cannot be seen in data set C and I can only see it when I use proc print
data c;
set a;
format x1 x2 x3 mypct.;
run;
@Ronein wrote:
I just don't understand why the format that I created cannot be seen in data set C and I can only see it when I use proc print
data c; set a; format x1 x2 x3 mypct.; run;
Start reading the docs to avoid such problems. The %-sign is always the first char of a special-formatting directive. The docs will tell you how to fix this.
proc format;
picture mypct (round) low-high='009.99%';
run;
http://support.sas.com/kb/38/001.html
This is correct, if it's not working, show how you're using it.
@Ronein wrote:
Hello
I have numeric values that present percentage.
I want to add % symbol to each of the numbers.
For example: instead of 2.14 we will see (format) 2.14%
I know to it by divide each number by 100 and then format it with percent9.2
My question is if there is another way to do it without divide by 100Data a; input x1 x2 x3; cards; 2.14 2.46 3.3 19.83 18.57 18.06 35.43 33.39 36.44 3.66 2.73 4.68 ; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.