SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
DavidKaib
Fluorite | Level 6

I would like to have the output from this code apply a percentage sign.

 

proc tabulate;

class URMG Department Period;

table (department all), Period*URMG*(pctn<URMG>)/printmiss misstext='0' nocellmerge;

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You will have to create a custom format to work with the Tabulate PCT functions.

You don't say how many decimals you might want. The example below will show 1 decimal point.

proc format;
picture custpct
0 - high ='0009.9%'
;
run;

Read the documentation of the Proc Format Picture statement for details.

How to modify your code to use the format:

proc tabulate;
   class URMG Department Period;
  table (department all), 
           Period*URMG*(pctn<URMG>*f=custpct.)
          /printmiss misstext='0' nocellmerge;
run;

The *F=<some format> overrides the default format for that particular PCTN or other percent calculations.

 

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

From the PROC TABULATE documentation, you just need to add a format.

 

format modifiers

define how to format values in cells. Use the asterisk (*) operator to associate a format modifier with the element (an analysis variable or a statistic) that produces the cells that you want to format. Format modifiers have the form

f=format

 

Tip Format modifiers have no effect on CLASS variables.
See For more information about specifying formats in tables, see Formatting Values in Tables.
Example
Sales*f=dollar8.2

 

In your case, you want the PERCENTw.d format

--
Paige Miller
ballardw
Super User

@PaigeMiller wrote:

From the PROC TABULATE documentation, you just need to add a format.

 

format modifiers

define how to format values in cells. Use the asterisk (*) operator to associate a format modifier with the element (an analysis variable or a statistic) that produces the cells that you want to format. Format modifiers have the form

f=format

 

Tip Format modifiers have no effect on CLASS variables.
See For more information about specifying formats in tables, see Formatting Values in Tables.
Example
Sales*f=dollar8.2

 

In your case, you want the PERCENTw.d format


The internal values that Tabulate applies the format to are multiplied by 100. So what would default to appearing as 15.1 will result in 1510% with wide enough Percentw.d format applied.

ballardw
Super User

You will have to create a custom format to work with the Tabulate PCT functions.

You don't say how many decimals you might want. The example below will show 1 decimal point.

proc format;
picture custpct
0 - high ='0009.9%'
;
run;

Read the documentation of the Proc Format Picture statement for details.

How to modify your code to use the format:

proc tabulate;
   class URMG Department Period;
  table (department all), 
           Period*URMG*(pctn<URMG>*f=custpct.)
          /printmiss misstext='0' nocellmerge;
run;

The *F=<some format> overrides the default format for that particular PCTN or other percent calculations.

 

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
  • 3 replies
  • 842 views
  • 0 likes
  • 3 in conversation