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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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