BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I am trying to create million format.

Please look at this example


proc format;
picture million (round fuzz=0)
0 -< 50000 = '00.0' (prefix='' mult=0.0)
50000 -< 1000000 = '00.0' (prefix='' mult=0.00001)
1000000 -< 1000000000='0000.0' (prefix='' mult=.00001);
run;


data tbl1 ;
x = 1200000;
y = 230700000;
z=1000;
format _all_ million. ;
run;


title;
proc print noobs;run;

 

 

In the print we can see that value of z is null  but we need to see value of 0.1.

What is the siolution and why did it happen?

 

 

One more question: I saw in internet using statment :    put (_all_)(=million.);

What is it doing ?

 

 

thanks

Ron

 

 

4 REPLIES 4
Kurt_Bremser
Super User

First of all, a mult factor of 0.0 will automatically set everything to zero.

Second, you need to force the display of a leading zero before the dot by using '9' instead of '0':

proc format;
picture million (round fuzz=0)
0 -< 50000 = '09.0' (prefix='' mult=0.001)
50000 -< 1000000 = '00.0' (prefix='' mult=0.00001)
1000000 -< 1000000000='0000.0' (prefix='' mult=.00001);
run;

If you run that with your other code, you get this result:

 x       y       z

1.2    230.7    0.1
Ronein
Meteorite | Level 14
Thank you
If we add another value than after proc print we are getting an error value
Please look what I need
ActualValue_In_USD
1,200,000
230,700,000
1,000
49,000
Desired Values In Millions
1.2
230.7
0.001
0.049


IF you run this code then you get for W value 4.9 but it is not
correct and need to be 0.049

proc format;
picture million (round fuzz=0)
0 -< 50000 = '09.0' (prefix='' mult=0.001)
50000 -< 1000000 = '00.0' (prefix='' mult=0.00001)
1000000 -< 1000000000='0000.0' (prefix='' mult=.00001);
run;
data tbl1 ;
x = 1200000;
y = 230700000;
z=1000;
w=49000;
format _all_ million. ;
run;
title;
proc print noobs;run;
Kurt_Bremser
Super User

Just tinker around with the mult factors and the number of decimal places, represented by the format characters 0 or 9:

proc format;
picture million (round fuzz=0)
  0 -< 1000000 = '9.000' (prefix='' mult=0.001)
  1000000 - high ='0000.0' (prefix='' mult=.00001)
;
run;

data test;
input x;
format x million. ;
cards;
1200000
230700000
1000
49000
;
run;

title;
proc print noobs;
run; 

 

ChrisHemedinger
Community Manager

Here's another approach that applies the "social media" rounding format: "k" for thousands, "M" for millions, etc.  I described it in this blog post.  Example code here:

 

/* Format your numbers like a social media superstar      */
/* Provided for example purposes only by Chris Hemedinger */
libname library (work);
proc format lib=library;
  value linkedin    
	500 - high ='500+'
	;
run;

data followers;
  length name $ 40 followers 8 displayed 8;
  format displayed linkedin.;
  infile datalines dsd;
  input name followers;
  displayed = followers;
datalines;
Chris Hemedinger, 776
Kevin Bacon, 100543
Norman Newbie, 3
Colleen Connector, 499
;
run;


proc format lib=library;
picture social (round)
 1E03-<1000000='000K' (mult=.001  )
 1E06-<1000000000='000.9M' (mult=.00001)
 1E09-<1000000000000='000.9B' (mult=1E-08)
 1E12-<1000000000000000='000.9T' (mult=1E-11);
run;

/* test data */ 
data likes (keep=actual displayed);
format actual comma20.
 displayed social.;
 do i=1 to 12;
  actual=16**i;
  displayed = actual;
  output;
 end;
run;

socialcount_output (1).png

 

 

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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
  • 4 replies
  • 8680 views
  • 2 likes
  • 3 in conversation