<?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 sql in a %Do loop with math calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445926#M111813</link>
    <description>&lt;P&gt;This may help:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-determine-logistic-regression-formula-from-estimates/td-p/120780" target="_self"&gt;How to determine logistic regression formula from estimates output&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Mar 2018 18:20:02 GMT</pubDate>
    <dc:creator>Stephen</dc:creator>
    <dc:date>2018-03-15T18:20:02Z</dc:date>
    <item>
      <title>proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445920#M111811</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;I use EG. I want to calculate p hat from my exist dataset. I write the equation in proc sql. The code is below, please help my why I come across this log error???&amp;nbsp; Is my do loop wrong? Or how can I detect my do loop problem? Or any other ways to calculate p hat? I need to add new column p_hat in the existing table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; variable=A,B,C &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let &lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;var_estimate=-0.0284,-0.0856,0.1242&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; score(create_table=, original_table=, intercept=);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;create table &amp;amp;create_table as&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;select *, (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;/(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;+exp(-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;*&amp;amp;intercept+&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(countw(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;variable."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; j=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(countw(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;var_estimate."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = j &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;catt(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;variable."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;i.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))*catt(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;var_estimate."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;j.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;))))as phat&lt;/P&gt;&lt;P&gt;from &amp;amp;original_table;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;%&lt;STRONG&gt;&lt;I&gt;score&lt;/I&gt;&lt;/STRONG&gt;(create_table=create_table1, original_table=training_newvar3,intercept=-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1.9190&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG ERROR:&lt;/P&gt;&lt;P&gt;))))as phat from &amp;amp;orig_table;&lt;/P&gt;&lt;P&gt;_&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,&lt;/P&gt;&lt;P&gt;a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please!!! Thank you so much for your help!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445920#M111811</guid>
      <dc:creator>michellekwai</dc:creator>
      <dc:date>2018-03-15T18:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445925#M111812</link>
      <description>&lt;P&gt;My guess is that you have too many or too few parentheses once the&amp;nbsp;macro is resolved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Place this statement at the top of your code,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then re-run your code and your SASLOG will be much more readable and most likely the mis-matched parenthesis will be easy to find.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445925#M111812</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-15T18:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445926#M111813</link>
      <description>&lt;P&gt;This may help:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-determine-logistic-regression-formula-from-estimates/td-p/120780" target="_self"&gt;How to determine logistic regression formula from estimates output&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445926#M111813</guid>
      <dc:creator>Stephen</dc:creator>
      <dc:date>2018-03-15T18:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445927#M111814</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;&lt;P&gt;Thank you so much for your reply! I add the code as you mentioned. The log error shows me this (shown below). I can't understand what caused the problem....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;26 ))))as phat from &amp;amp;orig_table;&lt;/P&gt;&lt;P&gt;_&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;MPRINT(SCORE): create table sandbox.create_table1 as select *, (1/(1+exp(-1*-1.9190+ ( ))) )as phat from sandbox.training_newvar3;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,&lt;/P&gt;&lt;P&gt;a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445927#M111814</guid>
      <dc:creator>michellekwai</dc:creator>
      <dc:date>2018-03-15T18:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445932#M111816</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;(1/(1+exp(-1*-1.9190+ &lt;FONT color="#FF0000"&gt;( )&lt;/FONT&gt;)) )&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can't have two parenthesis with nothing in between them.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445932#M111816</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-15T18:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445934#M111817</link>
      <description>&lt;P&gt;In macro language, i can never equal j.&amp;nbsp; They are different letters.&amp;nbsp; You might try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &amp;amp;i = &amp;amp;j %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445934#M111817</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-15T18:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445938#M111818</link>
      <description>&lt;P&gt;I really appreciate your help, Paige. As you said, it seems like I write some wrong do loop between the parathesis... Any idea how to fix the do loop problem. I want to create a new p_hat column, just adding in existing table. I think my logic is right to generate the multiplication of variable*estimate. But why sas can not show my do loop??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regard,&lt;/P&gt;&lt;P&gt;Michelle&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445938#M111818</guid>
      <dc:creator>michellekwai</dc:creator>
      <dc:date>2018-03-15T18:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445946#M111820</link>
      <description>&lt;P&gt;The easiest thign to do is to get code working &lt;EM&gt;without macros&lt;/EM&gt; on just one iteration of the loop. Then, since that works, you know&amp;nbsp; the parentheses are correct, and it would be easy enough to turn it into a macro that loops. If you have that working code, show it to us and we ought to be able to figure out what the macro should do.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445946#M111820</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-15T18:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445951#M111821</link>
      <description>&lt;P&gt;I think the problem is very obvious now. The log error show below, and as a very beginning sas user, I may ask a tiny question, Do you know how to add "+" sign bwtween every var*estimate multiplication, so I can get a summary of those many multiplication...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MPRINT(SCORE): proc sql noprint;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the invoked macro "SCORE".&lt;/P&gt;&lt;P&gt;26 catt(%scan("&amp;amp;variable.",&amp;amp;i.,","))*catt(%scan("&amp;amp;var_estimate.",&amp;amp;j.,","))&lt;/P&gt;&lt;P&gt;____&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;MPRINT(SCORE): create table sandbox.create_table1 as select *, (1/(1+exp(-1*-1.9190+ ( catt(DF5_ATM_C_DR_1P)*catt(-0.0284) catt(&lt;/P&gt;&lt;P&gt;DF6_TOTALSERV)*catt(-0.0856) catt(LAG1_NSF_C_1P)*catt(0.1242) catt(LAG1_TOTALACCTS)*catt(0.00516)&lt;/P&gt;&lt;P&gt;catt(LAG1_TOTALSERV)*catt(-0.1438) catt(LAG2_FEE_A_WV_1P)*catt(0.000109) catt(LAG2_TOTALSERV)*catt(-0.1703)&lt;/P&gt;&lt;P&gt;catt(LAG3_DBT_C_1P)*catt(0.00166) catt(LAG3_RATE)*catt(0.0272) catt(LAG4_FEE_A_WV_1P)*catt(0.000248)&lt;/P&gt;&lt;P&gt;catt(LAG7_TOTALSERV)*catt(-0.0883) ))))as phat from sandbox.training_newvar3;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN,&lt;/P&gt;&lt;P&gt;CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 18:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445951#M111821</guid>
      <dc:creator>michellekwai</dc:creator>
      <dc:date>2018-03-15T18:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445960#M111823</link>
      <description>&lt;P&gt;I think your program has gotten a little too complex.&amp;nbsp; This code contains more than is needed (while failing to add the + signs):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(countw(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;variable."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; j=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(countw(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;var_estimate."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = j &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;catt(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;variable."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;i.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))*catt(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;var_estimate."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;j.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this variation.&amp;nbsp; Remove the plus sign following &amp;amp;INTERCEPT, check whether four closing parens should be three closing parens, then use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(countw(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;variable."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; j=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(countw(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;var_estimate."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;i = &amp;amp;j &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp; + %scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&amp;amp;variable.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;i.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)*&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&amp;amp;var_estimate.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;j.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 19:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445960#M111823</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-15T19:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445961#M111824</link>
      <description>&lt;P&gt;I really appreciate Astounding!!!! It works!!! Thank you so much! You are right. It is too complicated!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 19:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445961#M111824</guid>
      <dc:creator>michellekwai</dc:creator>
      <dc:date>2018-03-15T19:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445965#M111825</link>
      <description>&lt;P&gt;If you have var_estimates same as variables then you don't need i &amp;amp; J. Avoid using CATT function for numeric variables and your missing '*' multiplication symbol for do loop. try something like this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let variable=Age,Height,weight;
%let var_estimate=-0.0284,-0.0856,0.1242;

%macro score(create_table=, original_table=, intercept=);
proc sql noprint;
create table &amp;amp;create_table as
select *, (1/(1+exp(-1*&amp;amp;intercept+
(%do i=1 %to %sysfunc(countw("&amp;amp;variable.",","));
%scan("&amp;amp;variable.",&amp;amp;i.,",")*%scan("&amp;amp;var_estimate.",&amp;amp;i.,",")*
%end;
1
)))) as phat
from &amp;amp;original_table;
quit;
%mend;
%score(create_table=test, original_table=sashelp.class, intercept=-1.9190);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 19:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445965#M111825</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-15T19:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445970#M111826</link>
      <description>&lt;P&gt;Thank you! you are right! The code you share is much more accurate and simple! Thank you SuryaKiran!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Michelle&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 19:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445970#M111826</guid>
      <dc:creator>michellekwai</dc:creator>
      <dc:date>2018-03-15T19:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445976#M111828</link>
      <description>&lt;P&gt;Note that the code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;shared is doing addition and the one I shared is doing&amp;nbsp;multiplication. Change it as your requirement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1/(1+exp(-1*&amp;amp;intercept+&lt;BR /&gt;(%do i=1 %to %sysfunc(countw("&amp;amp;variable.",","));&lt;BR /&gt;%scan("&amp;amp;variable.",&amp;amp;i.,",")*%scan("&amp;amp;var_estimate.",&amp;amp;i.,",") &lt;STRONG&gt;*&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This resolves to&amp;nbsp;1/(1+exp(-1*-1.9190+ ( Age*-0.0284 &lt;STRONG&gt;*&lt;/STRONG&gt; Height*-0.0856&lt;STRONG&gt;*&lt;/STRONG&gt; weight*0.1242&lt;STRONG&gt;* 1&lt;/STRONG&gt; )))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(1/(1+exp(-1*&amp;amp;intercept+&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(%do i=1 %to %sysfunc(countw("&amp;amp;variable.",","));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;STRONG&gt;+&lt;/STRONG&gt; %scan("&amp;amp;variable.",&amp;amp;i.,",")*%scan("&amp;amp;var_estimate.",&amp;amp;i.,",")&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This resolves to&amp;nbsp;1/(1+exp(-1*-1.9190+ (+Age*-0.0284+ Height*-0.0856+ weight*0.1242 )))&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 19:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445976#M111828</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-15T19:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql in a %Do loop with math calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445978#M111829</link>
      <description>&lt;P&gt;Yes. I understand what you said. Even though I need to solve the addition problem, but you really give me&amp;nbsp;good idea about what I should do about same number of variables. It helps to&amp;nbsp;simplify the code. Thank you again!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Michelle&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2018 19:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-in-a-Do-loop-with-math-calculation/m-p/445978#M111829</guid>
      <dc:creator>michellekwai</dc:creator>
      <dc:date>2018-03-15T19:50:53Z</dc:date>
    </item>
  </channel>
</rss>

