I'm trying to create a format that will convey a sense of scale for the data I'm working with. If the number is >= 1000 I want to add K
as a suffix, and represent it in '000s. Eg. 123456
would be 123K
.
This is what I have so far but clearly I'm misunderstanding something fundamental becuase the numbers going in don't look anything like the numbers coming out:
proc format;
picture abbrev
0 = '0'
0 -< 1000 = '000'
1000 - high = '0,000,000k' (mult=.0001)
;
run;
%put %sysfunc(sum(123456.0),abbrev.) /*SHOULD BE SOMETHING LIKE 123K */
%sysfunc(sum(12345.60),abbrev.) /*SHOULD BE SOMETHING LIKE 12.3K */
%sysfunc(sum(1234.560),abbrev.) /*SHOULD BE SOMETHING LIKE 1.3K */
%sysfunc(sum(123.4560),abbrev.) /*SHOULD BE SOMETHING LIKE 123 */
%sysfunc(sum(12.34560),abbrev.) /*SHOULD BE SOMETHING LIKE 12 */
%sysfunc(sum(1.234560),abbrev.) /*SHOULD BE SOMETHING LIKE 1 */
;
First, you made a math error; mult is .001 for 1000, not .0001.
Second, if you want the decimal, you have to understand picture a bit better. Picture is what it says: a picture. It does not have the 'add decimals as necessary' of something like BEST., or even COMMA. It only provides the decimal you ask for in the picture. But, you also have to adjust your mult for it - the picture takes the digits left of the decimal only, and places a new decimal on top of it.
With no decimal (see the .001):
proc format;
picture abbrev
0 = '0'
0 -< 1000 = '000'
1000 - high = '0,000,000k' (mult=.001)
;
run;
%put %sysfunc(sum(123456.0),abbrev.) /*SHOULD BE SOMETHING LIKE 123K */
%sysfunc(sum(12345.60),abbrev.) /*SHOULD BE SOMETHING LIKE 12.3K */
%sysfunc(sum(1234.560),abbrev.) /*SHOULD BE SOMETHING LIKE 1.3K */
%sysfunc(sum(123.4560),abbrev.) /*SHOULD BE SOMETHING LIKE 123 */
%sysfunc(sum(12.34560),abbrev.) /*SHOULD BE SOMETHING LIKE 12 */
%sysfunc(sum(1.234560),abbrev.) /*SHOULD BE SOMETHING LIKE 1 */
;
With a decimal (see it's now .01, since the decimal comes from the ones digit after multiplying):
proc format;
picture abbrev
0 = '0'
0 -< 1000 = '000'
1000 - high = '0,000,000.0k' (mult=.01)
;
run;
%put %sysfunc(sum(123456.0),abbrev.) /*SHOULD BE SOMETHING LIKE 123K */
%sysfunc(sum(12345.60),abbrev.) /*SHOULD BE SOMETHING LIKE 12.3K */
%sysfunc(sum(1234.560),abbrev.) /*SHOULD BE SOMETHING LIKE 1.3K */
%sysfunc(sum(123.4560),abbrev.) /*SHOULD BE SOMETHING LIKE 123 */
%sysfunc(sum(12.34560),abbrev.) /*SHOULD BE SOMETHING LIKE 12 */
%sysfunc(sum(1.234560),abbrev.) /*SHOULD BE SOMETHING LIKE 1 */
;
See SAS Documentation for more details and a good example.