Hello:
I have the following codes. I would like to format the ratio shown as .12345 and create percent variable as 12.35%. Please advice how to do it. Thanks.
data poverty;
set poverty;
BelowPoverty=Under50+Under50to99;
Ratio=belowpoverty/total;
run;
format ratio 7.5;
That would actually get you 0.12345, not .12345. But eliminating the leading zero is trouble, and not worth the effort.
To create a PERCENT variable:
percent = put(ratio, percent9.2);
The width needs to be 9, because the percent formats automatically include a leading and a trailing blank (and you may have to be able to express 100%). Because of the leading blank, you may want to apply this statement as well:
percent = left(percent);
Note that PERCENT will be a character field, not something that you can use to perform math.
format ratio percent8.2;
Try a FORMAT statement.
List of formats are available here:
format ratio 7.5;
That would actually get you 0.12345, not .12345. But eliminating the leading zero is trouble, and not worth the effort.
To create a PERCENT variable:
percent = put(ratio, percent9.2);
The width needs to be 9, because the percent formats automatically include a leading and a trailing blank (and you may have to be able to express 100%). Because of the leading blank, you may want to apply this statement as well:
percent = left(percent);
Note that PERCENT will be a character field, not something that you can use to perform math.
Thank you so much for your great help!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.