BookmarkSubscribeRSS Feed
kimdukes77
Obsidian | Level 7

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;

3 REPLIES 3
Ksharp
Super User

Add an option before PROC FORMAT.

 

options  cmplib=work.functions ;

proc format...........

.......

kimdukes77
Obsidian | Level 7

Works a treat - thank you!

FreelanceReinh
Jade | Level 19
@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1127 views
  • 0 likes
  • 3 in conversation