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

Hi

Is there any format in SAS that writes the numeric value with a space as thousands separator? 

NLNUMIw. writes with a comma (,) 1,000,000

Commax writes with a dot (.) 1.000.000

But I try to find solution for 1 000 000

Any help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Try this way:

proc format;
picture mythous00_
  low-<0  = '000 000 000 009.00' (prefix="-" multiplier=100)
       0  = '0'
  0<-high = '000 000 000 009.00' (multiplier=100)
;

picture mythous_
  low-<0  = '000 000 000 009' (prefix="-")
       0  = '0'
  0<-high = '000 000 000 009' ;

run;

data _null_;
  do i = -2 to 10;
    x = 10**i ;
    y = -10**i ;
    put @1 i @6 "v1" @10 x mythous00_. @30 y mythous00_. @50 x best32.2; 
    put @1 i @6 "v2" @10 x mythous_.   @30 y mythous_.   @50 x best32.2;
  end;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

Create your own PICTURE format:

proc format;
picture mythous(dig3sep=' ')
  low-high = '000000000009' 
;
run;

Untested, posted from my tablet.

J_J_J
Obsidian | Level 7

Thank you, Kurt. It's with a syntax error.

yabwon
Onyx | Level 15

according to doc. it should be:

proc format;
picture mythous
  low-high = '000000000009' (DIG3SEP=' ')
;
run;

but, log seems to be showing something else:

1    proc format;
2    picture mythous
3      low-high = '000000000009' (DIG3SEP=' ')
4    ;
NOTE: Format MYTHOUS has been output.
5    run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


6
7
8    data _null_;
9      do i = -2 to 10;
10       x = 10**i ;
11       y = -10**i ;
12       put @1 i @10 x mythous. @30 x best32.;
13     end;
14   run;

-2                  0                                    0.01
-1                  0                                     0.1
0                   1                                       1
1                  10                                      10
2                 100                                     100
3                1000                                    1000
4               10000                                   10000
5              100000                                  100000
6             1000000                                 1000000
7            10000000                                10000000
8           100000000                               100000000
9          1000000000                              1000000000
10        10000000000                             10000000000
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

I did some testing, and I think the dig3sep (and decsep too) wont force a character for separator in a sequence like "000000000009" but  rather the instruct SAS which character is used as separator in a sequence. If you compare those tow:

proc format;
  picture mythousA
  low-high = '000.000.000.009#000' (DIG3SEP='.' decsep="#")
;
  picture mythousB
  low-high = '000.000.000.009#000' /*(DIG3SEP='.' decsep="#")*/
;
run;


data _null_;
  do i = -2 to 10;
    x = 10**i ;
    y = -10**i ;
    put @1 i @10 x mythousA. @30 x mythousB. @50 x best32.;
  end;
run;

you will see they are giving different results:

1    proc format;
2      picture mythousA
3      low-high = '000.000.000.009#000' (DIG3SEP='.' decsep="#")
4    ;
NOTE: Format MYTHOUSA has been output.
5      picture mythousB
6      low-high = '000.000.000.009#000' /*(DIG3SEP='.' decsep="#")*/
7    ;
NOTE: Format MYTHOUSB has been output.
8    run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


9
10
11   data _null_;
12     do i = -2 to 10;
13       x = 10**i ;
14       y = -10**i ;
15       put @1 i @10 x mythousA. @30 x mythousB. @50 x best32.;
16     end;
17   run;

-2                     0#010              10#000                             0.01
-1                     0#100             100#000                              0.1
0                      1#000           1.000#000                                1
1                     10#000          10.000#000                               10
2                    100#000         100.000#000                              100
3                  1.000#000       1.000.000#000                             1000
4                 10.000#000      10.000.000#000                            10000
5                100.000#000     100.000.000#000                           100000
6              1.000.000#000   1.000.000.000#000                          1000000
7             10.000.000#000  10.000.000.000#000                         10000000
8            100.000.000#000 100.000.000.000#000                        100000000
9          1.000.000.000#000               0#000                       1000000000
10        10.000.000.000#000               1#E16                      10000000000
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted
      by the "BEST" format.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

In the first case SAS is able to understand meaning of the dot and hash correctly.

 

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

Try this way:

proc format;
picture mythous00_
  low-<0  = '000 000 000 009.00' (prefix="-" multiplier=100)
       0  = '0'
  0<-high = '000 000 000 009.00' (multiplier=100)
;

picture mythous_
  low-<0  = '000 000 000 009' (prefix="-")
       0  = '0'
  0<-high = '000 000 000 009' ;

run;

data _null_;
  do i = -2 to 10;
    x = 10**i ;
    y = -10**i ;
    put @1 i @6 "v1" @10 x mythous00_. @30 y mythous00_. @50 x best32.2; 
    put @1 i @6 "v2" @10 x mythous_.   @30 y mythous_.   @50 x best32.2;
  end;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



J_J_J
Obsidian | Level 7

Thank you, yabwon! It works!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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