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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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