<?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: Macro programming with reference variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723794#M224668</link>
    <description>&lt;P&gt;If some better formatting rules were used, such as macro language in lower case, and user names (tables variables) in uppercase, the syntax would become more obvious.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEMP;
  set TEST;
  %cipoiss(0.95,OBS,DENOMINATOR,1000, RATE, LL, LU);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that some values are hard-coded, while other values use whatever values are in the variables defined.&lt;/P&gt;
&lt;P&gt;This will also be visible in the log in the code generated by option MPRINT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Mar 2021 07:48:54 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-03-05T07:48:54Z</dc:date>
    <item>
      <title>Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723757#M224655</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I came across the following macro function (shortened), but don't know what it should be called or what I should look for to understand more of it.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro CIpoisson(cl, x, N, base, rate, ll,lu);
	if (&amp;amp;x) &amp;lt; 0 then
	do;  
		&amp;amp;rate = .;
   		&amp;amp;ll = .;
   		&amp;amp;lu = .;
	end;
	else if not(0 &amp;lt; (&amp;amp;cl) &amp;lt; 1) then
	do;
		&amp;amp;rate = (&amp;amp;base)*(&amp;amp;x)/(&amp;amp;N);
		&amp;amp;ll = .;
   		&amp;amp;lu = .;
	end; 
   else do;
   &amp;amp;xx = ...;
   end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;And it works like&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 	input obs denominator;
	datalines;
	-1 100
	46 7400
	3210 762787
	14 400
;
run;

data tempb;
set test;
%cipoiss(0.95,obs,denominator,1000, rate,ll,lu);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It looks like all the variables serve as data holders or reference variables.&lt;/P&gt;&lt;P&gt;Are there any reference books that introduce such macro programmings?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 04:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723757#M224655</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2021-03-05T04:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723773#M224658</link>
      <description>&lt;P&gt;The developer should have included documentation with his macro.&lt;/P&gt;
&lt;P&gt;As it is, we can see that it performs calculations in a data step.&lt;/P&gt;
&lt;P&gt;Turn option MPRINT on to see the code generated by the macro in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for learning the SAS macro language, there are many resources on the web.&lt;/P&gt;
&lt;P&gt;The macro here doesn't do a lot, so is a good way to get your toes wet.&lt;/P&gt;
&lt;P&gt;It simply adds code to the data step using the values given as parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 05:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723773#M224658</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-05T05:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723781#M224662</link>
      <description>&lt;P&gt;I think my confusion is around&lt;/P&gt;&lt;PRE&gt;rate, ll, lu&lt;/PRE&gt;&lt;P&gt;these three parameters, in which they are macros, but serve as variable names as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because they are doing nothing in the function arguments, but only get updated once the calculation done.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The way how they are being used here looks exactly like pass-by-reference in C++.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 06:13:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723781#M224662</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2021-03-05T06:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723794#M224668</link>
      <description>&lt;P&gt;If some better formatting rules were used, such as macro language in lower case, and user names (tables variables) in uppercase, the syntax would become more obvious.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEMP;
  set TEST;
  %cipoiss(0.95,OBS,DENOMINATOR,1000, RATE, LL, LU);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that some values are hard-coded, while other values use whatever values are in the variables defined.&lt;/P&gt;
&lt;P&gt;This will also be visible in the log in the code generated by option MPRINT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 07:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723794#M224668</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-05T07:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723803#M224674</link>
      <description>&lt;P&gt;Looks like, without rate, ll, lu in the macro argument works too. Just wondering whether they are redundant in the original code or there is any benefits to put them there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cipoiss2(x, D);
	if &amp;amp;x &amp;lt; 0 then do;
		rate = .;
		ll = .;
		lu = .;
	end;
	else do;
		rate = &amp;amp;x/&amp;amp;D;
		ll = (&amp;amp;x - 1.96*sqrt(&amp;amp;x))/&amp;amp;D;
		lu = (&amp;amp;x + 1.96*sqrt(&amp;amp;x))/&amp;amp;D;
	end;
%mend;

data tempb;
set test;
%cipoiss2(obs,denominator);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 08:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723803#M224674</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2021-03-05T08:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723859#M224705</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133203"&gt;@windlove&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I think my confusion is around&lt;/P&gt;
&lt;PRE&gt;rate, ll, lu&lt;/PRE&gt;
&lt;P&gt;these three parameters, in which they are macros, but serve as variable names as well.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133203"&gt;@windlove&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the macro &lt;EM&gt;definition&lt;/EM&gt; (&lt;FONT face="courier new,courier"&gt;%macro CIpoisson(&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;)&lt;/FONT&gt;...) these are &lt;STRONG&gt;names of macro parameters&lt;/STRONG&gt; (i.e. macro variables). In the macro &lt;EM&gt;call&lt;/EM&gt; (&lt;FONT face="courier new,courier"&gt;%CIpoisson(&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;)&lt;/FONT&gt;) these are &lt;STRONG&gt;text strings&lt;/STRONG&gt; which happen to coincide with the parameter names (unlike &lt;FONT face="courier new,courier"&gt;obs&lt;/FONT&gt; vs. &lt;FONT face="courier new,courier"&gt;x&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;denominator&lt;/FONT&gt; vs. &lt;FONT face="courier new,courier"&gt;N&lt;/FONT&gt;) and which are passed as values to those macro variables and eventually used as &lt;STRONG&gt;names of DATA step variables&lt;/STRONG&gt; in the DATA step code generated by the macro. Thus the user has the flexibility to choose arbitrary variable names, e.g., &lt;FONT face="courier new,courier"&gt;UCL&lt;/FONT&gt; for &lt;FONT face="courier new,courier"&gt;lu&lt;/FONT&gt;. This can be useful, for example, if there was already an existing variable named &lt;FONT face="courier new,courier"&gt;lu&lt;/FONT&gt; in dataset &lt;FONT face="courier new,courier"&gt;test&lt;/FONT&gt; so that hardcoding "&lt;FONT face="courier new,courier"&gt;lu&lt;/FONT&gt;" (instead of "&lt;FONT face="courier new,courier"&gt;&amp;amp;lu&lt;/FONT&gt;") in the macro code would cause a name conflict.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 13:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723859#M224705</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-05T13:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723862#M224706</link>
      <description>&lt;P&gt;Maybe it would be less confusing if the macro call used the parameter names in the call.&amp;nbsp; One of the nice features of SAS macros is that you can always use the parameter names in the macro call, even for parameters that the macro has defined such that they can be called by position also.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your macro call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%cipoiss(0.95,obs,denominator,1000, rate,ll,lu);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Could be re-written as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%cipoiss
(cl=0.95
,x=obs
,n=denominator
,base=1000
,rate=rate
,ll=ll
,lu=lu
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now it is clearer that for the N parameter the user is passing in the variable name DENOMINATOR and for the RATE parameter the user is passing in the variable name RATE.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 13:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723862#M224706</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-05T13:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723887#M224717</link>
      <description>&lt;P&gt;OK. I understand now.&lt;/P&gt;&lt;P&gt;So they are just normal macro variables.&lt;/P&gt;&lt;P&gt;I think I just didn't expect that variable names in the left-hand side "=" should be changed through function arguments like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 15:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723887#M224717</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2021-03-05T15:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming with reference variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723923#M224729</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133203"&gt;@windlove&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;OK. I understand now.&lt;/P&gt;
&lt;P&gt;So they are just normal macro variables.&lt;/P&gt;
&lt;P&gt;I think I just didn't expect that variable names in the left-hand side "=" should be changed through function arguments like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Modifying the SAS code that you want to run is the whole point of using the macro processor.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 17:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-with-reference-variables/m-p/723923#M224729</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-05T17:28:36Z</dc:date>
    </item>
  </channel>
</rss>

