SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bbenbaruch
Quartz | Level 8

Is there a format that will make sure that all output has the same number of digits to the right of the decimal point regardless of whether the value is less than 1%?  t seems to me that there should be something like a PERCENTZ.d format that will output a 0 to the left of the decimal point when appropriate.  Is there such a format?

 

Example: a column of values output using the PERCENT7.3 format:

   7.44%
   3.36%
   .242%

What I want:

   7.44%
   3.36%
   0.24%

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

PERCENT7.2 ought to give you the desired results

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

PERCENT7.2 ought to give you the desired results

--
Paige Miller
Reeza
Super User
Your width is too small. You've set it to 7 total but it's not enough to hold all the values so the zero is truncated. Make the width larger to avoid the issue.

Percent12.3 works with original data.

If you have any chance of having negative values you want to make it wider as well.

I would recommend using percent12.2 as your format. That's usually wide enough to avoid most issues.
bbenbaruch
Quartz | Level 8

Thanks.  I feel silly because I forgot the difference between PERCENTw.d and PERCENTNw.d.  (The difference is in how negative percentages are output.  PERCENTw.d outputs them in parentheses requiring accounting for 2 additional characters in the output.)

 

PERCENTN7.2 will also work -- when I know that all of my percentages will be between 99.99% and -99.99%.

Rick_SAS
SAS Super FREQ

For a summary of the PERCENTw.d and PERCENTNw.d formats and a discussion of field widths, see "Those tricky PERCENT formats."

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 2680 views
  • 1 like
  • 4 in conversation