BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cho8
Calcite | Level 5

Need below data in Million Dollar format.

 

 

Data:

629777257.73063114.55747687382.3131371401.09
548907467.67475029.27430882553.5726616491.86

 

 

Expected Format;

 

 $     630 MM $          3 MM $        48 MM $        31 MM
 $     549 MM $          7 MM $        31 MM $        27 MM
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

It'd be nice if you didn't change your requirements as you go.

This does what you asked. Modify to suit if your needs change again.

proc format;
  picture million (ROUND)
    low  -< 0    = '000,000,000,000,009)' (prefix="($ ")
    0            = 'Zero'
    0    -  1e6  = '1 Million'
    1e6 <-< 10e6 = '000,000,009 M'        (prefix=" $ " mult=0.000001)
    10e6 - high  = '000,000,009 Million'  (prefix=" $ " mult=0.000001)
  ;
run;

data _null_;
  A =          1.2; putlog A= million. ;
  A = -629777257.2; putlog A= million. ;
  A =  629777257.2; putlog A= million. ;
  A =    3063114.2; putlog A= million. ;
run;

A=1 Million
A=($ 629,777,257)
A=$ 630 Million
A=$ 3 M

View solution in original post

16 REPLIES 16
Reeza
Super User

This can get you started

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=proc&docsetTarget=n0kl9qj...

 

proc format;   
   picture bigmoney (fuzz=0)
      1E06-<1000000000='0000 M' (prefix='$' mult=.000001)
      1E09-<1000000000000='0000 B' (prefix='$' mult=1E-09)
      1E12-<1000000000000000='0000 T' (prefix='$' mult=1E-012);
run;
data mult;
   do i=5 to 12;
      x=16**i;
      put x=comma20. x= bigmoney.;
   end;
run;

Results:

LOG
Formatted Millions, Billions, and Trillions Dollar Amounts
x=1,048,576 x=$1 M
x=16,777,216 x=$16 M
x=268,435,456 x=$268 M
x=4,294,967,296 x=$4 B
x=68,719,476,736 x=$68 B
x=1,099,511,627,776 x=$1 T
x=17,592,186,044,416 x=$17 T
x=281,474,976,710,656 x=$281 T

This isn't exactly what you want but should be enough for you to figure out the solution from here.

 


@Cho8 wrote:

Need below data in Million Dollar format.

 

 

Data:

629777257.7 3063114.557 47687382.31 31371401.09
548907467.6 7475029.274 30882553.57 26616491.86

 

 

Expected Format;

 

 $     630 MM  $          3 MM  $        48 MM  $        31 MM
 $     549 MM  $          7 MM  $        31 MM  $        27 MM

 

yabwon
Onyx | Level 15

I had similar idea 🙂

proc format;
  picture milion (ROUND)
  low - high = '000,000,000 MM' (prefix="$ " mult=0.000001)
  ;
run;

B-)

_______________
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



Cho8
Calcite | Level 5

proc format;
picture bigm (ROUND)
low - high = '000,000,000,000 M' (prefix="$ " mult=0.000001)
;
run;

 

I have defined format like the above..

 

but iam not able to dispaly  the below number in Million format. Please advise

 

2.047219393619E-09

 

 

 

yabwon
Onyx | Level 15

Hi @Cho8 ,

 

You right, with the one I provided you won't be do display this number, sorry for that. I've mad an update.

proc format;
  picture milion (ROUND)
  low -< 0  = '000,000,009 MM' (prefix="-$ " mult=0.000001)
  0         = '0 MM'
  0 <- high = '000,000,009 MM' (prefix=" $ " mult=0.000001)
  ;
run;

data _null_;
  x = 2.047219393619E-09;
  put x = /
      x = 32.16 /
      x = milion. ;
run;

All the best

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



Cho8
Calcite | Level 5

-64684149.4007373

 

the negative number to be displayed like ($ 64,684,149). it should not take  Million format.

 

 

yabwon
Onyx | Level 15

Ok, one more update:

proc format;
  picture milion (ROUND)
  low -< 0  = '000,000,000,000,009)' (prefix="($ ")
  0         = '0 MM'
  0 <- high = '000,000,009 MM' (prefix=" $ " mult=0.000001)
  ;
run;

data _null_;
  x = 2.047219393619E-09;
  put x = /
      x = 32.16 /
      x = milion. ;

  x = -64684149.4007373;
  put x = /
      x = 32.16 /
      x = milion. ;

  x = 64684149.4007373;
  put x = /
      x = 32.16 /
      x = milion. ;
run;

B-)

_______________
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



Cho8
Calcite | Level 5

Thanks..

 

its not converting ENotation into $M Format..

 

 

its giving Enotation value..

 

 

yabwon
Onyx | Level 15

it does:

1    data _null_;
2      x = 6.46841494007373E7;
3      put x = /
4          x = 32.16 /
5          x = milion. ;
6    run;

x=64684149.401
x=64684149.4007373000000000
x=$ 65 MM
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 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



Cho8
Calcite | Level 5

i have to store it in datset alongside other variables,to use it for further calculations.

 

i have to use  FORMAT stmt..

 

 

but while using FORMAT it still showing Enotation..

 

is there a way to display using FORMAT..stmt.

yabwon
Onyx | Level 15

Could you share some code? It will be easier.

 

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



Cho8
Calcite | Level 5

 

 

 

 

 

 

 

 

yabwon
Onyx | Level 15

When I run this:

proc format;
  picture bigm (ROUND)
  low -< 0  = '000,000,000,000,009)' (prefix="($ ")
  0         = '0 MM'
  0 <- high = '000,000,009 MM' (prefix=" $ " mult=0.000001)
  ;
run;

data test;
  Stress2008 = 2.047219393619E-09;
  Base2 = 600599374.795993;
  format Base2 Stress2008 bigm.;
run;
proc print data = test;
run;

I get the following output:

       The SAS System

Obs    Stress2008     Base2

 1       $ 0 MM      $ 601 MM

I don't understand what is not ok?

 

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



Reeza
Super User

It's very unusual to see three SET statements the way you've shown except in fairly complex programming for interleaving. Given the remainder of your code, I suspect you're doing something incorrectly at that stage.

 


@Cho8 wrote:

data euc.thirdrow(rename=(Base2=Base)); /* Should correct format of Base2*Base */
keep '$NCL'n Base2 Stress2008 ;
set euc.roll;
set euc.asofsep_sum1;
set euc.thirdrow_1 (drop='$NCL(Q3''20)'n);

Stress2008=(Stress/(Base2*Base));
format Base2  Stress2008 bigm.;

run;

 

Stress2008=2.047219393619E-09

Base2 =600599374.795993($601M)

 

i need Stress2008 also in $M format..

 

i can display Base2 as $601M using FOrmat bigm.,but not Stress2008

 

 

 


 

novinosrin
Tourmaline | Level 20

Hi @Cho8  Here is a solution by @ChrisNZ  that you may have already checked. Just in case-

 

https://communities.sas.com/t5/SAS-Programming/Format-Billions-as-0-0-B/td-p/491433

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 16 replies
  • 3491 views
  • 5 likes
  • 5 in conversation