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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

8 REPLIES 8
Reeza
Super User

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. 

ChrisNZ
Tourmaline | Level 20

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.

ChrisNZ
Tourmaline | Level 20

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.

 

 

 

aj34321
Quartz | Level 8

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

 

 

ChrisHemedinger
Community Manager

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

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
andreas_lds
Jade | Level 19

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

ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
ChrisNZ
Tourmaline | Level 20

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

 

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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