BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Bal23
Lapis Lazuli | Level 10

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

9 REPLIES 9
ballardw
Super User

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;
Bal23
Lapis Lazuli | Level 10

this does not work.

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

set WORK.

 

 

Reeza
Super User

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

 

Use INPUT() function to do so. 

Tom
Super User Tom
Super User

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);
Reeza
Super User

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.

Reeza
Super User

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.

Reeza
Super User

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

Reeza
Super User

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;
Bal23
Lapis Lazuli | Level 10

Thank you for your code.

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 40603 views
  • 0 likes
  • 4 in conversation