<?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: How to specify multiple terms in the macro with proc nlmixed in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754054#M80794</link>
    <description>The second version has become so flexible and efficient that I can utilize it in other cases with minor modifications. I can't thank you enough for showing me the good piece of code.</description>
    <pubDate>Wed, 14 Jul 2021 12:42:12 GMT</pubDate>
    <dc:creator>windy</dc:creator>
    <dc:date>2021-07-14T12:42:12Z</dc:date>
    <item>
      <title>How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754013#M80786</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am seeking help to write a macro using proc nlmixed with multiple terms.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to define the model in proc nlmixed with multiple dummies (let say D1, D2, D3, D4, D5) and the interaction terms between variable X with each of those dummy variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code can be written normally as:&lt;/P&gt;
&lt;P&gt;proc nlmixed data=have;&lt;/P&gt;
&lt;P&gt;eta = int + a1*D1 + a2* D2 + a3*D3 + a4*D4 + a5*D5 + b1*D1*X + b2*D2*X + b3*D3*X + b4*D4*X + b5*D5*X;&lt;/P&gt;
&lt;P&gt;......&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My actual model is much longer than that since I have up to 9 dummies and 2 variables X. In total, I will need to specify around 30 terms in my model.&amp;nbsp;Is there way to make my model specification shorter which allows me to modify the model easily?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Windy.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 09:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754013#M80786</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2021-07-14T09:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754023#M80787</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297250"&gt;@windy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could write a little utility macro like this (just an example -- feel free to modify it)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro terms(pattern,n);
%local i;
%do i=1 %to &amp;amp;n;
+ %sysfunc(tranwrd(&amp;amp;pattern,#,&amp;amp;i))
%end;
%mend terms;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then write the model like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;eta = int %terms(a#*D#,5) %terms(b#*D#*X,5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That is, the wildcard "#" in the first argument of the macro is replaced by numbers 1, 2, ..., &lt;EM&gt;n&lt;/EM&gt; (&lt;EM&gt;n&lt;/EM&gt;=second argument of the macro) and the resulting model terms are concatenated with " + ".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 10:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754023#M80787</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-14T10:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754034#M80788</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is working beautifully. Thank you so much for helping me again. I really appreciate it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 11:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754034#M80788</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2021-07-14T11:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754035#M80789</link>
      <description>&lt;P&gt;Sorry for bothering you again&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What should I do if I want to remove the + sign?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 11:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754035#M80789</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2021-07-14T11:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754037#M80790</link>
      <description>&lt;P&gt;The plus sign is just text in the macro. If you remove it,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro terms(pattern,n);
%local i;
%do i=1 %to &amp;amp;n;
%sysfunc(tranwrd(&amp;amp;pattern,#,&amp;amp;i))
%end;
%mend terms;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the result will look something like this (log excerpt)&lt;/P&gt;
&lt;PRE&gt;99   %put eta = int %terms(a#*D#,5) %terms(b#*D#*X,5);
eta = int a1*D1 a2*D2 a3*D3 a4*D4 a5*D5 b1*D1*X b2*D2*X b3*D3*X b4*D4*X b5*D5*X&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 11:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754037#M80790</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-14T11:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754039#M80791</link>
      <description>&lt;P&gt;I saw it. By the way, I need the + sign there though.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking that I can remove the + sign in the first macro and use it later in eta, but the code is not resolved.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you again for your support.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jul 2021 11:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754039#M80791</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2021-07-14T11:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754042#M80792</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297250"&gt;@windy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I was thinking that I can remove the + sign in the first macro and use it later in eta, ...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is actually a good idea because it makes the macro a bit more flexible (for situations where the plus sign is not appropriate).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, with the second version of the macro you can make the plus sign an optional part of the first argument in the macro call:&lt;/P&gt;
&lt;PRE&gt;108  %put eta = int %terms(&lt;STRONG&gt;+&lt;/STRONG&gt; a#*D#,5) %terms(&lt;STRONG&gt;+&lt;/STRONG&gt; b#*D#*X,5);
eta = int + a1*D1 + a2*D2 + a3*D3 + a4*D4 + a5*D5 + b1*D1*X + b2*D2*X + b3*D3*X + b4*D4*X + b5*D5*X&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jul 2021 11:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754042#M80792</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-07-14T11:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to specify multiple terms in the macro with proc nlmixed</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754054#M80794</link>
      <description>The second version has become so flexible and efficient that I can utilize it in other cases with minor modifications. I can't thank you enough for showing me the good piece of code.</description>
      <pubDate>Wed, 14 Jul 2021 12:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-specify-multiple-terms-in-the-macro-with-proc-nlmixed/m-p/754054#M80794</guid>
      <dc:creator>windy</dc:creator>
      <dc:date>2021-07-14T12:42:12Z</dc:date>
    </item>
  </channel>
</rss>

