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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.