I was creating a custom format to handle the fact that the SAS built in format sizekmg does not handle terabytes. It works as intended, with the exception that I can't get it to change the number of decimals for anything over 1TB. As in, I have the following code:
%let onetb=%sysevalf(1024**4); *1099511627776;
proc format ;
picture sizekmgt (round)
0 -< &onetb. = [sizekmg10.2]
other = '00000.99TB' (multiplier=%sysevalf(100/&onetb.)) ;
*Multiplier 100 because we want 2 decimals;
run;
My issue is that if I use e.g. sizekmgt10.3 it will not change the number of decimals. I have tried a couple of different versions, but I can't get it to do what I want. Does anyone have any ideas on what I can do to fix this?
And thanks to @ChrisNZ for the main example, I stole it and added the round part to it.
I don't think you can do that.
You could make a second format that does 3 decimal places.
%let onetb=%sysevalf(1024**4); *1099511627776;
proc format ;
* Multiplier 100 because we want 2 decimals ;
picture sizekmgt (round)
0 -< &onetb. = [sizekmg11.2]
other = '00009.99TB' (multiplier=%sysevalf(100/&onetb.))
;
picture size3kmgt (round)
0 -< &onetb. = [sizekmg11.3]
other = '00009.999TB' (multiplier=%sysevalf(1000/&onetb.))
;
run;
data _null_;
do k=1 to 5;
i=1024**k - 512**(k-1) ;
put k (3*i) (sizekmgt. +1 size3kmgt. +1 :comma24.);
end;
run;
Results
124 data _null_; 125 do k=1 to 5; 126 i=1024**k - 512**(k-1) ; 127 put k (3*i) (sizekmgt. +1 size3kmgt. +1 :comma24.); 128 end; 129 run; 1 1.00KB 0.999KB 1,023 2 1023.50KB 1023.500KB 1,048,064 3 1023.75MB 1023.750MB 1,073,479,680 4 1023.88GB 1023.875GB 1,099,377,410,048 5 1023.94TB 1023.938TB 1,125,831,187,365,888
I think your issue is the number of digit selectors in decimal positions. Once those are satisfied that's all the format displays.
If you need 3, 4 or more decimals try a different Picture statement with the number of digit selectors to match, or at least one in the final decimal position.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.