<?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: DOSUBL : Problem when using macro variables after CALL EXECUTE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226308#M40725</link>
    <description>You cannot use call execute with a macro like this. You would have to run it as a dosubl also. You should really rethink your entire design here. Not good.</description>
    <pubDate>Fri, 18 Sep 2015 14:58:25 GMT</pubDate>
    <dc:creator>FriedEgg</dc:creator>
    <dc:date>2015-09-18T14:58:25Z</dc:date>
    <item>
      <title>DOSUBL : Problem when using macro variables after CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226294#M40724</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've been trying to write a macro using DOSUBL to return a string so I can use it directly in DATA Step. Inside the DOSUBL block, I call another macro using CALL EXECUTE which will return 2 macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the macro which returns 2 macro variables :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Binomial_p(r,n,alpha=0.05);

/* Create data set param6 */
data param6;
	r = &amp;amp;r.;
    n = &amp;amp;n.;
    alpha = &amp;amp;alpha.;
    p = r/n;
	q = 1 - p;
    z = probit(1-alpha/2);
    output;
    max_idx = alpha/2;
	min_idx = 1 - alpha/2;

	do j = 0.000001 to 0.999999 by 0.00001;
		if (r &amp;gt; 0 and r &amp;lt; n) then a2 = 0.5*probbnml(j,n,r-1) + 0.5*probbnml(j,n,r);
		output;
	end;
run;

/* Create data set min &amp;amp; max */
proc sql;
	create table max as
	select max(j) as upper6
	from param6		
	where a2 &amp;gt; max_idx and r &amp;gt; 0 and r &amp;lt; n;

	create table min as
	select min(j) as lower6
	from param6		
	where a2 &amp;lt;= min_idx and r &amp;gt; 0 and r &amp;lt; n;
quit;

/* Store lower6 &amp;amp; upper6 into macro variables for future use */
%global lower6 upper6;
data ci6;
	merge param6(obs=1) min max;
	if r = 0 then do;
		lower6 = 0;
		upper6 = 1 - alpha**(1/n);
	end;
	if r = n then do;
		lower6 = alpha**(1/n);
		upper6 = 1;
	end;
	call symputx("lower6",lower6);
	call symputx("upper6",upper6);
run;

/* Delete unnecessary data sets */
proc datasets nolist; 
	delete param6 min max ci6; 
run;

%mend Binomial_p;

/*
%Binomial_p(r=81,n=263,alpha=0.05);
%put lower6=&amp;amp;lower6. upper6=&amp;amp;upper6.;
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Here is the main DOSUBL block :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro CI_Proportion(r,n,method,alpha=0.05);

%local ci;
%let rc = %sysfunc(dosubl(%str(

data _null_;
	/* Define some values */
    r = &amp;amp;r.;
    n = &amp;amp;n.;
    alpha = &amp;amp;alpha.;
    p = r/n;
	q = 1 - p;
    z = probit(1-alpha/2);
	/* 6.  Binomial-based, Mid-p (Binomial_p) */
	if &amp;amp;method. = "Binomial_p" then do;
		call execute('%Binomial_p(r=&amp;amp;r.,n=&amp;amp;n.,alpha=&amp;amp;alpha.);');
		lower = &amp;amp;lower6.;
		upper = &amp;amp;upper6.;
	end;
	/* Store ci into macro variable */
	ci = strip(put(r,10.)) || " " || strip(put(p,10.4)) || "(" || strip(put(lower,10.4)) || "-" || strip(put(upper,10.4)) || ")";
	call symputx("ci",ci);
run;

)));
/* Return macro variable ci */
&amp;amp;ci.

%mend CI_Proportion;

%put %CI_Proportion(r=81,n=263,method="Binomial_p",alpha=0.05);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I ran into 2 errors :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR 386-185: Expecting an arithmetic expression.
ERROR 200-322: The symbol is not recognized and will be ignored.
386: LINE and COLUMN cannot be determined.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Apparent symbolic reference LOWER6 not resolved.
WARNING: Apparent symbolic reference UPPER6 not resolved.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the second error, I think I can't use 2 macro variables after CALL EXECUTE because they don't exist yet. Is it correct ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first one, I couldn't find where is the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any input !!!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 14:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226294#M40724</guid>
      <dc:creator>monsieur</dc:creator>
      <dc:date>2015-09-18T14:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: DOSUBL : Problem when using macro variables after CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226308#M40725</link>
      <description>You cannot use call execute with a macro like this. You would have to run it as a dosubl also. You should really rethink your entire design here. Not good.</description>
      <pubDate>Fri, 18 Sep 2015 14:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226308#M40725</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2015-09-18T14:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: DOSUBL : Problem when using macro variables after CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226309#M40726</link>
      <description>&lt;P&gt;Watch out for inteaction between local and global symbol tables when using DOSSUBL.&lt;/P&gt;&lt;P&gt;See this thread.&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/DOSUBL-scope-of-returned-macro-variables/m-p/138691#M27993" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/DOSUBL-scope-of-returned-macro-variables/m-p/138691#M27993&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 15:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226309#M40726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-18T15:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: DOSUBL : Problem when using macro variables after CALL EXECUTE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226325#M40727</link>
      <description>&lt;P&gt;To build, somewhat, on your post from yesterday, try using PROC FCMP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp;

subroutine Binomial_p(r, n, alpha, upper6, lower6);
   outargs upper6, lower6;
   p = r/n;
   q = 1 - p;
   z = probit(1-alpha/2);

   if r = 0 then do;
      lower6 = 0;
	  upper6 = 1 - alpha**(1/n);
   end;
   else if r = n then do;
      lower6 = alpha**(1/n);
	  upper6 = 1;
   end;
   else do;
      length max_idx min_idx rc j a2 8;
      max_idx = alpha/2;
      min_idx = 1 - alpha/2;
      
      declare hash h(ordered:'d');
      declare hiter hi('h');
         rc = h.definekey('j');
         rc = h.definedata('a2');
      rc = h.definedone();

      do j = 0.000001 to 0.999999 by 0.00001;
         if (r &amp;gt; 0 and r &amp;lt; n) then do;
	        a2 = 0.5*probbnml(j,n,r-1) + 0.5*probbnml(j,n,r);
		    if a2 &amp;lt;= a2 &amp;gt; max_idx then rc = h.add();
	     end;
      end;

      rc = hi.first();
      if a2 &amp;gt; max_idx then upper6 = j;
      rc = hi.last();
	  if a2 &amp;lt;= min_idx then lower6 = j;
   end;
endsub;

function CI_Proportion(r, n, method $, alpha) $;
   p = r/n;
   q = 1 - p;
   z = probit(1-alpha/2);

   length upper lower 8;
   if method = "Binomial_p" then call Binomial_p(r,n,alpha,upper,lower);

   ci = strip(put(r,10.)) || " " || strip(put(p,10.4)) || "(" || strip(put(lower,10.4)) || "-" || strip(put(upper,10.4)) || ")";
   return(ci);
endsub;

ci_proportion = CI_Proportion(81,263,"Binomial_p",0.05);
put ci_proportion=;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2015 15:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DOSUBL-Problem-when-using-macro-variables-after-CALL-EXECUTE/m-p/226325#M40727</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2015-09-18T15:31:54Z</dc:date>
    </item>
  </channel>
</rss>

