You can create your own format and use a function to create the formatted value.
You can find more on in the doc here: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1eyyzaux0ze5ln1k03gl338avbj.htm
An example for this (change the logic according to your needs):
/*
* create the function
*/
proc fcmp outlib=work.myformats.mypkg;
function generalFormat(number) $ 32;
length returnValue $ 32;
select;
when ( number = int(number) ) do;
returnValue = put(number, commax32.);
end;
when ( scan( put(round(number, 0.1), 32.1), -1, ".") = "0" ) do;
returnValue = put(number, commax32.);
end;
otherwise do;
returnValue = put(number, commax32.1);
end;
end;
return (left(returnValue));
endsub;
run;
/*
* make the new function available
*/
options cmplib=work.myformats;
/*
* create some data and test the function
*/
data have;
do value = 1000200, 200.25, 10, 500.3, 10.03;
value2 = value;
/* test out just the function */
newValue = generalFormat(value);
output;
end;
run;
/*
* create a format using the function
*/
proc format;
value gfmt (default=32)
low - high = [generalFormat()]
;
run;
/*
* test it out
*/
proc print data=have;
format value2 gfmt.;
run;
But why have some numbers with decimals and others not? Makes reading more difficult, I think.
... View more