BookmarkSubscribeRSS Feed
hf_
Fluorite | Level 6 hf_
Fluorite | Level 6

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.

2 REPLIES 2
Tom
Super User Tom
Super User

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
ballardw
Super User

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 384 views
  • 0 likes
  • 3 in conversation