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.

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

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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-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
  • 8 replies
  • 3544 views
  • 4 likes
  • 5 in conversation