## How to put a comma in the numbers of the output

Solved
Super Contributor
Posts: 345

# How to put a comma in the numbers of the output

[ Edited ]

i know there is put statement, that can add "," to the number, thus, 2378912 can be changed to 2378,912

PUT INCOME2 comma8.2;

variable Number and percent

expect, number will be like, 1234,569

percent will be like, 0.63

my question is I am not using proc sql, nor any data steps. I am using proc freq and hope the output be like 2378,129 instead of 2378129

since the code will be

proc freq,

proc print

I do not know where I can put commax statement, or how to change the format of numbers, to add "," to the total number, but without dicimal, 2378,129 not 2378,129.0. however, in the same output, i want to the percent will be 0.63

would anybody provide a sample code?

Thanks.

Accepted Solutions
Solution
‎10-10-2017 01:16 PM
Super User
Posts: 13,583

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

[ Edited ]

For your variable values use a FORMAT statement.

``````Proc freq data=have;
tables income;
format income Comma8.2;
run;``` ```

or similar in proc print or just about any procedure that displays your variabls in the output.

If you want to change the appearance of values calculated by the procedure, such as the count or percent in Proc Freq, then you will have to customize the table template the procedure uses.

Alternative from @Reeza that uses PROC TABULATE:

Here's sample code using comma and dollar format.

``````proc tabulate data=sashelp.prdsal2;
title 'Total Sales, By Quarter and Country';
class country quarter;
var predict;
table (country='' all='Global'),
quarter=''*predict=''*(sum='Sum'*f=dollar12.2 n='Count'*f=comma12.);
run;quit;``````

All Replies
Solution
‎10-10-2017 01:16 PM
Super User
Posts: 13,583

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

[ Edited ]

For your variable values use a FORMAT statement.

``````Proc freq data=have;
tables income;
format income Comma8.2;
run;``` ```

or similar in proc print or just about any procedure that displays your variabls in the output.

If you want to change the appearance of values calculated by the procedure, such as the count or percent in Proc Freq, then you will have to customize the table template the procedure uses.

Alternative from @Reeza that uses PROC TABULATE:

Here's sample code using comma and dollar format.

``````proc tabulate data=sashelp.prdsal2;
title 'Total Sales, By Quarter and Country';
class country quarter;
var predict;
table (country='' all='Global'),
quarter=''*predict=''*(sum='Sum'*f=dollar12.2 n='Count'*f=comma12.);
run;quit;``````
Super Contributor
Posts: 345

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

this does not work.

ERROR: You are trying to use the numeric format COMMA with the character variable gainage in data

set WORK.

Super User
Posts: 23,771

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

You have to convert your variable to a numeric type if you want to apply a numeric format.

Use INPUT() function to do so.

Super User
Posts: 8,117

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

You cannot apply a numeric format to a character variable.  You need to convert it to a number first.

You might want to add a step where you convert gainage to a number and then store the result back.

``````gainage=put(input(strip(gainage),32.),comma8.2);
``````
Super User
Posts: 23,771

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

But if you store it as character your numbers won't sort properly in tables.

Something to keep in mind. There may be some workarounds but it's easier to keep it as a number, IMO.

Super User
Posts: 23,771

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

But if you store it as character your numbers won't sort properly in tables.

Something to keep in mind. There may be some workarounds but it's easier to keep it as a number, IMO.

Super User
Posts: 23,771

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

Use proc tabulate for the output, it allows you to control the format in the output.

Super User
Posts: 23,771

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

[ Edited ]

Here's sample code using comma and dollar format.

``````proc tabulate data=sashelp.prdsal2;
title 'Total Sales, By Quarter and Country';
class country quarter;
var predict;
table (country='' all='Global'),
quarter=''*predict=''*(sum='Sum'*f=dollar12.2 n='Count'*f=comma12.);
run;quit;``````
Super Contributor
Posts: 345

## Re: hOW TO PUT COMMA TO THE NUMBERS IN THE OUTPUT

I guess there should be another way of changing the template. I recall I was using another code and it worked very well but I got a warning/note saying that I was changing the template. Then due to my comptuer problem, maybe because of installtion of something, setting changed, it changes back.

I am thinking I am looking for a code to change a template, that means, I expect all my table output has the format, that is 567,900, instead of 567900

Any code of changing the template, instead of a single variables. That will be too much work

🔒 This topic is solved and locked.