Sizekmg format to show TB

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 79
Accepted Solution

Sizekmg format to show TB

Hi All,

 

Does any one know how to use SizeKMG format to display values in Terabyte.

 

For now, it only prrints KB, MB & GB. 

 

Need extension for TB.

 

Any suggestions?


Accepted Solutions
Solution
‎08-31-2017 12:33 AM
Community Manager
Posts: 3,362

Re: Sizekmg format to show TB

Posted in reply to andreas_lds

My example there was not about "computer Ks" -- multiples of 1024.  My example was more about rounding in the social media sphere, where a "k" is 1000.  It's not usable as-is for your purpose, but I shared it as an example of what a complete format definition might look like.  The sizekmg format does the proper math for this case.

View solution in original post


All Replies
Super User
Posts: 22,874

Re: Sizekmg format to show TB

You can create a nested format

Quick skeleton:

 

proc format ;

value customTB

Low - ##### =[sizekgm]

other = ...;

run;

 

You can use PROC FCMP to embed a calculation if needed. 

PROC Star
Posts: 2,231

Re: Sizekmg format to show TB

[ Edited ]

Like this?


%let onetb=%sysevalf(1024**4);

proc format ;
  picture sizekmgt 0       -< &onetb. = [sizekmg10.]
                   &onetb. -  high    = '000000.9TB' (multiplier=%sysevalf(1/&onetb.)) ;
run;
                                                                
data _null_; B=2222e6; C=2222e9; putlog (B C) (sizekmgt.); run; 

Result: 2GB 2TB

Modify the picture to suit.

PROC Star
Posts: 2,231

Re: Sizekmg format to show TB

While you are at it, change the KB to kB.

 

Americans (not only) are still confused with the metric system's units (K is Kelvin, k is kilo).  Smiley Happy

 

Even better, you can redefine the units to kiB and MiB.

 

 

 

Frequent Contributor
Posts: 79

Re: Sizekmg format to show TB

Thanks Chris. This is what exactly i want, but now how do i format this, like if i have to pass on as below format

sizekmgt10.2;

 

So if a number is 1599511627776 then the output should be  1.59 TB and  if i use format  sizekmgt10.4; then the output should be 1.5995 TB

 

 

Community Manager
Posts: 3,362

Re: Sizekmg format to show TB

Looks like you are pretty close with the solution from @ChrisNZ, but here's another approach that builds a format from scratch, documented in this blog post.

 

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.png

Super Contributor
Posts: 500

Re: Sizekmg format to show TB

Posted in reply to ChrisHemedinger

Unfortunately the fortmatted value in the 4th obs is wrong. 65536 Bytes are 64 kiB.

Solution
‎08-31-2017 12:33 AM
Community Manager
Posts: 3,362

Re: Sizekmg format to show TB

Posted in reply to andreas_lds

My example there was not about "computer Ks" -- multiples of 1024.  My example was more about rounding in the social media sphere, where a "k" is 1000.  It's not usable as-is for your purpose, but I shared it as an example of what a complete format definition might look like.  The sizekmg format does the proper math for this case.

PROC Star
Posts: 2,231

Re: Sizekmg format to show TB

[ Edited ]

@aj34321 That's not how picture formats work sadly. You choose the position of the decimal point when you build the format.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 368 views
  • 4 likes
  • 5 in conversation