• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / SAS Percent Format – Formatting Number as Percent in SAS Dataset

SAS Percent Format – Formatting Number as Percent in SAS Dataset

January 21, 2022 Leave a Comment

In SAS, we can format numbers as percentages very easily using the built-in SAS PERCENTw.d format or creating our own format with PROC Format.

/* Using Built-in SAS PERCENTw.d format */
data data_new;
    format num dollar10.2;
    set data;
run;

/* Creating our own percent format */
proc format;
    picture our_percent_format(round)
        low -< 0 = '000009.9%' (prefix='-' mult=1000)
        0 - high = '000009.9%' (mult=1000)
;
run;

data data_new;
    format num our_percent_format;
    set data;
run;

When working with data which represents percentages, many times we want to display the data in a way that makes sense. For most cases, this means adding percent signs and multiplying by 100 where appropriate.

In SAS, we can use the built-in PERCENTw.d format to format numeric values with a trailing percent sign and a value which is multiplied by 100.

Let’s say we have some data which represents a percentage. We can use the PERCENTw.d format to format the data to show the data formatted like a percentage point.

data data;
    format num percent10.2;
    input num;
    datalines;
0.123
1.789
0.504
0.981
 0.48
;
run;

/* Output */
1   12.30%
2  178.90%
3   50.40%
4   98.10%
5   48.00%

Depending on how our data is set up, the built-in percent format can work, but other times it might make sense to create our own percent format.

Creating a User-Defined SAS Percent Format with PROC Format

With PROC format, we are easily able to define number formats so our data can be displayed cleaner. Another useful format is the percent format.

We could use the standard SAS percent format, but sometimes you want the ability to customize formats.

With PROC format, we can build our own percent format.

We can create a format for this easily with PROC format in the following way. We will create a picture format and pass the “round” option so that the format rounds the data first, and then displays the percents.

proc format;
    picture our_percent_format(round)
        low -< 0 = '000009.9%' (prefix='-' mult=1000)
        0 - high = '000009.9%' (mult=1000)
;
run;

Depending on the scale of your data, you may want to change the multiplier.

Let’s see how this looks when it is applied to some data.

data data;
    format num our_percent_format.;
    input num;
    datalines;
0.123
1.789
0.504
0.981
 0.48
;
run;

/* Output */
      num
1   12.3%
2  178.9%
3   50.4%
4   98.1%
5   48.0%

As you can see from above, this looks much better. You can play with the multiplier and the format to get exactly what you want for your user defined percent format.

Hopefully this article has been helpful for you to learn how to use the built-in SAS format for percentages and how to create your own percent format in SAS.

Other Articles You'll Also Like:

  • 1.  How to Combine Datasets Vertically in SAS
  • 2.  Round Number to Nearest Integer in SAS
  • 3.  mod Function in SAS – Find Remainder of 2 Numbers After Division
  • 4.  SAS rename Statement – How to Rename Variables in a Data Step
  • 5.  SAS intnx – Add or Subtract Time from Date Variables in SAS Data Step
  • 6.  SAS weekday function – Get Day of Week from Date Variable
  • 7.  SAS year function – Get Year from Date Variable
  • 8.  Using SAS to Find Mean by Group with PROC MEANS
  • 9.  SAS if then else – Write Conditional Expressions for Multiple Conditions
  • 10.  SAS month function – Get Month from Date Variable

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy