BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Rhodochrosite | Level 12

Hello Experts,

 

I'm wondering if there is a numeric format with spaces. I apply the format comma10.2 and, for example, my result is  673,380.10, I would like to have 673 380.10.

 

Thank you!

 

[KB] Edit: changed "without" to "with"

 
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You will need to make your own using PROC FORMAT.

 

proc format;
picture spaces (default=10)
 -99999.99-<0 ='00 009.99' (prefix='-')
 0-999999.99 ='000 009.99'
 other=[best10.2]
;
run;

Then you test it out.

 

data test;
  input x @@;
  y=x ;
  format x comma10.2 y spaces.;
cards;
123456.78  0 1 10 100 1000 10000 -1 -10 -1000
;

proc print;
run;

View solution in original post

15 REPLIES 15
PaigeMiller
Diamond | Level 26

Why?

--
Paige Miller
Tom
Super User Tom
Super User

You will need to make your own using PROC FORMAT.

 

proc format;
picture spaces (default=10)
 -99999.99-<0 ='00 009.99' (prefix='-')
 0-999999.99 ='000 009.99'
 other=[best10.2]
;
run;

Then you test it out.

 

data test;
  input x @@;
  y=x ;
  format x comma10.2 y spaces.;
cards;
123456.78  0 1 10 100 1000 10000 -1 -10 -1000
;

proc print;
run;
SASdevAnneMarie
Rhodochrosite | Level 12
Thank you, Tom,
Could you explain me 0-999999.99 and '000 009.99' because I need to do the same things for comma22.4 and comma16.2 format. Thank you!
Tom
Super User Tom
Super User

Each 0 or 9 indicates where the digits should be placed.  When you use 9 the digit is always printed even when it is zero.  But when you use 0 the zero digits are printed as spaces.  So by ending it with 09.99 it will always print the ones place and the tenths and hundreds places.

 

For the first range I tried to pick the largest magnitude negative number that could print in N characters as the lower bound and used open ended upper bound of zero.  And used the PREFIX= option to get it to print the hyphen.  Remember to leave room for the hyphen.

 

For the second range I used zero as the lower bound and the upper bound was the largest number that could appear in N spaces.

 

But you should also look at the ROUND option on the format definition. I believe that without that picture formats will truncate the values.  So 1.347 will print as 1.34 instead of 1.35.

 

So with rounding in place I doubt that the values I picked are exactly the right lower and upper bounds.  So you might need to experiment to determine what boundaries will work for you.

 

Or perhaps you are certain your actual values will never approach those extremes and so do not need to worry about it.

 

SASdevAnneMarie
Rhodochrosite | Level 12
Thank you Tom!
ballardw
Super User

@SASdevAnneMarie wrote:

Hello Experts,

 

I'm wondering if there is a numeric format without spaces. I apply the format comma10.2 and, for example, my result is  673,380.10, I would like to have 673 380.10.

 

Thank you!

 

I have to say that your comment about "without spaces" confuses me because you say that you "like to have 673 380.10"  which clearly has a space between the threes. 

SASdevAnneMarie
Rhodochrosite | Level 12
Hello Ballardw,

"With" spaces. Unfortunately, I can not modify my message.
SASdevAnneMarie
Rhodochrosite | Level 12
Thank you, Kurt!
ballardw
Super User

@SASdevAnneMarie wrote:
Hello Ballardw,

"With" spaces. Unfortunately, I can not modify my message.

You should be able to edit any of the posts you have made. There should be a block of three lines next to the subject of the post. Roll your cursor over the block of lines and and "edit message" or "edit reply" should appear. Click and the edit option opens the message or reply.

FreelanceReinh
Jade | Level 19

@ballardw wrote:

You should be able to edit any of the posts you have made.


Hello @ballardw,

 

While Super Users like you deservedly enjoy this elevated privilege, the rest of us have been allowed, since 2022, only a limited time window ("within a day of posting") to edit our posts.

Ksharp
Super User

You could try SAS built-in format NLNUM.  if your local zone support it .

Tom
Super User Tom
Super User

@Ksharp wrote:

You could try SAS built-in format NLNUM.  if your local zone support it .


I tried that and did not find any locale that used spaces.

filename code temp;
filename log2 temp;

data _null_;
  set sashelp.vlocale;
  file code ;
  put 'options ' locale= :$quote. ';run;'
      '%put ' locale :$quote. '=%qsysfunc(putn(123456.78,nlnum10.2));'
  ;
run;
options nosource nonotes ps=200;
proc printto log=log2 ;run;
%include code /nosource2 ;
proc printto log=log; run;
options source notes locale=en_US;

data locale;
  infile log2 dsd truncover dlm='=' ;
  input locale :$30. string :$10. ;
run;

proc freq;
 tables string ;
run;

Screenshot 2026-02-17 at 11.00.10 PM.png

Tom
Super User Tom
Super User

Actually there are some but they use non-breaking space instead of space.  So when using ENCODING=UTF8 you will need to make the width of the format specification larger because it takes two bytes to store a non-breaking space with that encoding.

 

The reason they did not appear in my earlier test is because the NLNUM format will remove the thousand separators when it needs more room to display the number in the required width.

filename code temp;
filename log2 temp;

data _null_;
  set sashelp.vlocale;
  file code ;
  put 'options ' locale= :$quote. ';run;'
      '%put ' locale :$quote. '=%qsysfunc(putn(123456.78,nlnum14.2));'
  ;
run;
options nosource nonotes ps=200;
proc printto log=log2 ;run;
%include code /nosource2 ;
proc printto log=log; run;
options source notes locale=en_US;

data locale;
  infile log2 dsd truncover dlm='=' ;
  input locale :$30. string :$14. ;
run;

proc freq;
 tables string ;
run;

proc print ;
where index(string,'C2A0'x);
run;

Screenshot 2026-02-18 at 1.41.52 PM.png

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 15 replies
  • 1064 views
  • 11 likes
  • 7 in conversation