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?
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.
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.
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.
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). 🙂
Even better, you can redefine the units to kiB and MiB.
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
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;
Unfortunately the fortmatted value in the 4th obs is wrong. 65536 Bytes are 64 kiB.
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.
@aj34321 That's not how picture formats work sadly. You choose the position of the decimal point when you build the format.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register 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.