BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
monsieur
Obsidian | Level 7

Hi everyone,

 

I've been trying to create a function using PROC FCMP which will return a confidence interval (CI) using Wilson method. I would like to use the CI directly in a DATA step or PROC SQL. Here is the function : 

  

proc fcmp outlib = work.funcs.CI;

function CI_Wilson(r,n,output $,fmt,alpha) $;
    /* Define some values */
	p = r/n;
	q = 1 - p;
    z = probit(1-alpha/2);
	/* CI Wilson */
   	lower = (2*r+z**2-(z*sqrt(z**2+4*r*q)))/(2*(n+z**2));
    upper = (2*r+z**2+(z*sqrt(z**2+4*r*q)))/(2*(n+z**2));        
	/* CI */
	if output = "proportion" then ci = strip(put(r,10.)) || " " || strip(put(p,10.4)) || "(" || strip(put(lower,10.4)) || "-" || strip(put(upper,10.4)) || ")";
	else if output = "percent" then ci = strip(put(r,10.)) || " " || strip(put(p*100,10.4)) || "(" || strip(put(lower*100,10.4)) || "-" || strip(put(upper*100,10.4)) || ")";
	return(ci);
endsub;

quit;

options cmplib = work.funcs;
data _null_;
	ci_proportion = CI_Wilson(81,263,"proportion",10.4,0.05);
	ci_percent = CI_Wilson(81,263,"percent",10.4,0.05);
	put ci_proportion;
	put ci_percent;
run;

 It works fine if I write directly 

strip(put(p,10.4))

but SAS will give me error if I try

strip(put(p,fmt))
ERROR 22-322: Expecting a format name.
ERROR 202-322: The option or parameter is not recognized and will be ignored.

 

Furthermore, I already wrote a similar macro using DOSUBL and it worked fine with "fmt" as a macro variable. I just think for a simple calculation like this, it would be faster using PROC FCMP. If someone can suggest a solution, it would be greatly appreciated !!!

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
FriedEgg
SAS Employee

You need to use the putn function, not put.

monsieur
Obsidian | Level 7
Thank you FriedEgg, it works like a champ.

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
  • 2 replies
  • 1096 views
  • 0 likes
  • 2 in conversation