I have inherited some code that creates a user-defined function and format (later used in proc tabulate statement) that is not working.
Can anyone help?
Code below:-
* Create a function that rounds small & missing numbers to zero (amended fromn standard supprnd function code as in this instance we need to create a numeric variable for later calculations);
proc fcmp outlib=work.functions.misc;
function suppf(x);
length y 16;
if ( missing(x) OR x in (1, 2) ) then y = 0; /* suppress disclosive values */
else do;
x2 = round(x, 5); /* round to nearest 5 */
y = put(x2, 32.);
end;
return(compress(y));
endsub;
/*Add function to round to nearest 10 for current cycle reporting*/
function suppt(x);
length y 16;
if ( missing(x) OR x in (1, 2) ) then y = 0; /* suppress disclosive values */
else do;
x2 = round(x, 10); /* round to nearest 5 */
y = put(x2, 32.);
end;
return(compress(y));
endsub;
/* suppress disclosive values, but do not round other values */
function suppr_s(x) $;
length y $30;
if ( missing(x) OR x in (1, 2) ) then y = '--'; /* suppress disclosive values */
else do;
y = put(x, 32.);
end;
return(compress(y));
endsub;
run;
proc format;
/* Format for rounding */
value supp_t
other = [suppt()]; /* suppress disclosive values & round to nearest 10 */
value supp_f
other = [suppf()]; /* suppress disclosive values & round to nearest 5 */
value suppress
other = [suppr_s()]; /* suppress disclosive values only */
quit;
Add an option before PROC FORMAT.
options cmplib=work.functions ;
proc format...........
.......
Works a treat - thank you!
@Ksharp wrote:
Add an option before PROC FORMAT.
options cmplib=work.functions ;
proc format...........
.......
... and use the function names as format names (see documentation), i.e. value suppt etc.
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.