<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PROC FCMP : Problem when passing a format to PUT inside a function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-FCMP-Problem-when-passing-a-format-to-PUT-inside-a-function/m-p/226073#M40654</link>
    <description>&lt;P&gt;You need to use the putn function, not put.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Sep 2015 15:23:41 GMT</pubDate>
    <dc:creator>FriedEgg</dc:creator>
    <dc:date>2015-09-17T15:23:41Z</dc:date>
    <item>
      <title>PROC FCMP : Problem when passing a format to PUT inside a function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-FCMP-Problem-when-passing-a-format-to-PUT-inside-a-function/m-p/226068#M40653</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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 :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;It works fine if I write directly&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;strip(put(p,10.4))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but&amp;nbsp;SAS will give me error if I try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;strip(put(p,fmt))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR 22-322: Expecting a format name.
ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;PROC FCMP.&amp;nbsp;If someone can suggest a solution, it would be greatly appreciated !!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 15:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-FCMP-Problem-when-passing-a-format-to-PUT-inside-a-function/m-p/226068#M40653</guid>
      <dc:creator>monsieur</dc:creator>
      <dc:date>2015-09-17T15:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP : Problem when passing a format to PUT inside a function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-FCMP-Problem-when-passing-a-format-to-PUT-inside-a-function/m-p/226073#M40654</link>
      <description>&lt;P&gt;You need to use the putn function, not put.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 15:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-FCMP-Problem-when-passing-a-format-to-PUT-inside-a-function/m-p/226073#M40654</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2015-09-17T15:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP : Problem when passing a format to PUT inside a function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-FCMP-Problem-when-passing-a-format-to-PUT-inside-a-function/m-p/226096#M40661</link>
      <description>Thank you FriedEgg, it works like a champ.</description>
      <pubDate>Thu, 17 Sep 2015 17:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-FCMP-Problem-when-passing-a-format-to-PUT-inside-a-function/m-p/226096#M40661</guid>
      <dc:creator>monsieur</dc:creator>
      <dc:date>2015-09-17T17:03:05Z</dc:date>
    </item>
  </channel>
</rss>

