BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

4 REPLIES 4
HB
Barite | Level 11 HB
Barite | Level 11

    format ratio percent8.2;

Astounding
PROC Star

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.

ybz12003
Rhodochrosite | Level 12

Thank you so much for your great help!

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1773 views
  • 3 likes
  • 4 in conversation