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"
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;
Why?
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;
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 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 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.
@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.
You could try SAS built-in format NLNUM. if your local zone support it .
@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;
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;
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →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.
Ready to level-up your skills? Choose your own adventure.