<?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: First loop through columns and then loop through through rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/684341#M207368</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;, now the error is&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: (execution) Invalid subscript or subscript out of range.&lt;/P&gt;&lt;P&gt;Additionally, how can change the IML code to caculate z value for each observation (more like the IML equivalent of "diff" command in OPTMODEL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Sep 2020 18:45:05 GMT</pubDate>
    <dc:creator>Jass_Banga</dc:creator>
    <dc:date>2020-09-16T18:45:05Z</dc:date>
    <item>
      <title>First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681697#M206224</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I want to loop first through columns and then through rows.&lt;/P&gt;&lt;P&gt;data test ;&lt;BR /&gt;input cat $ cat3 cat4 cat5 cat6 cat7 cat8 num_rat ;&lt;BR /&gt;cards;&lt;BR /&gt;cat3 0 -1.78 -2.68 -3.06 -3.4 -3.83 1885&lt;BR /&gt;cat4 0 2.12 -2.15 -2.63 -2.94 -3.34 3151&lt;BR /&gt;cat5 0 2.45 1.16 -1.39 -1.99 -2.54 246&lt;BR /&gt;cat6 0 2.48 1.92 1.19 -1.13 -2.39 80&lt;BR /&gt;cat7 0 2.68 2.32 1.82 1.52 -1.56 89&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example: I need to sum for cat3 (row) by first subtraction (0 + -1.78)*1885 + (-1.78 + -2.68)*1885 + (-2.68 + -3.06)*1885 + (-3.06 + -3.4)*1885 + (-3.4 + -3.83)*1885&lt;/P&gt;&lt;P&gt;and then calculate for all the rows (cat4, cat5, cat6, cat7) and then sum all the rows together and minimize them like (min(sum_rows).&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 17:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681697#M206224</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-04T17:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681701#M206227</link>
      <description>&lt;P&gt;In a data step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;row_sum=(cat3+cat8+2*sum(of cat4-cat7))*num_rat;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To sum or find the minimum of all the values of row_sum, use PROC SUMMARY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=whatever;
    var row_sum;
    output out=want sum=sum_sum_rows min=min_sum_rows;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 17:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681701#M206227</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-04T17:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681723#M206243</link>
      <description>Thanks Paige, but I think this is not the required answer. I expect the do loop to run through each variable (columns) and calculate the function. Also I intend to minimize the function to one variable (lets say a z_score which can be said to (0 + -1.78)*1885*Z + (-1.78 + -2.68)*1885 *Z + (-2.68 + -3.06)*1885*Z + (-3.06 + -3.4)*1885*Z + (-3.4 + -3.83)*1885*Z.&lt;BR /&gt;&lt;BR /&gt;Sorry I should have mentioned "Z" in my original post.</description>
      <pubDate>Fri, 04 Sep 2020 18:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681723#M206243</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-04T18:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681732#M206250</link>
      <description>&lt;P&gt;Show the output exactly as you expect it to appear, including variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might also help to describe WHY and WHAT this calculation represents. Many times people take some example from a text book and don't realize that SAS has specialized functions or procedures to generate the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One might suspect that your 1885 value might represent an N of some sort but simple algebra reduces that to&lt;/P&gt;
&lt;PRE&gt;(1885 *Z)*[(0 + -1.78)+(-1.78 + -2.68)+(-2.68 + -3.06)+(-3.06 + -3.4)+(-3.4 + -3.83)]&lt;/PRE&gt;
&lt;P&gt;And anything that looks like&lt;/P&gt;
&lt;PRE&gt; (x+x1)+(x1+x2)+(x2+x3)+(x3+x4)
  = x+2x1+2x2+2x3+x4&lt;/PRE&gt;
&lt;P&gt;So that can be considerably reduced. Which looks like that "loop" may not be needed at all.&lt;/P&gt;
&lt;P&gt;Unless you mean a Z that changes, in which case you need to provide way more details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are "standardizing" values you might look into proc STDIZE.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 19:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681732#M206250</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-04T19:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681738#M206253</link>
      <description>&lt;P&gt;I understand Brad, and apologize for not being clear earlier.&lt;/P&gt;&lt;P&gt;Below is the equation I need Minimize:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jass_Banga_0-1599247701338.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49027i68E397D69977A21B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jass_Banga_0-1599247701338.png" alt="Jass_Banga_0-1599247701338.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;where&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jass_Banga_1-1599247740442.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49028i33CCC6579ED88A98/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jass_Banga_1-1599247740442.png" alt="Jass_Banga_1-1599247740442.png" /&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jass_Banga_2-1599247801377.png" style="width: 239px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49029iB2D8D162BF28E489/image-dimensions/239x60?v=v2" width="239" height="60" role="button" title="Jass_Banga_2-1599247801377.png" alt="Jass_Banga_2-1599247801377.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The matrix is&amp;nbsp;data test ;&lt;/P&gt;&lt;P&gt;data test ;&lt;BR /&gt;input cat $ cat3 cat4 cat5 cat6 cat7 cat8 ;&lt;BR /&gt;cards;&lt;BR /&gt;cat3 0 -1.78 -2.68 -3.06 -3.4 -3.83&lt;BR /&gt;cat4 0 2.12 -2.15 -2.63 -2.94 -3.34&lt;BR /&gt;cat5 0 2.45 1.16 -1.39 -1.99 -2.54&lt;BR /&gt;cat6 0 2.48 1.92 1.19 -1.13 -2.39&lt;BR /&gt;cat7 0 2.68 2.32 1.82 1.52 -1.56&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%let rho = 0.8; *It will be changed after every run*;&lt;BR /&gt;%let z= 0.89; * It should be minimized*;&lt;/P&gt;&lt;P&gt;DATA TEST1;&lt;BR /&gt;SET test;&lt;BR /&gt;Array Cat_C(6) cat3-cat8;&lt;BR /&gt;Array Cat_g(5) catg3-catg7;&lt;BR /&gt;do i= 1to 5;&lt;BR /&gt;cat_g(i)= num_rat * ((((CDF('Normal', Cat_C(i+1))-CDF('NORMAL',Cat_C(i))-&lt;BR /&gt;((CDF('NORMAL', ((Cat_C(i+1) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))-(CDF ('NORMAL', ((Cat_C(i) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))))**2))/&lt;BR /&gt;(((CDF('NORMAL', ((Cat_C(i+1) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))-(CDF ('NORMAL', ((Cat_C(i) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho)))))*&lt;BR /&gt;(1-((CDF('NORMAL', ((Cat_C(i+1) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))-(CDF ('NORMAL', ((Cat_C(i) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))))));&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where x(g+1) is the movement from cat3 to cat4. and rho needs to be any fixed number (say 0.8) and z needs to be minimized using any initial number (say 0.89).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 19:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681738#M206253</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-04T19:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681739#M206254</link>
      <description>&lt;P&gt;Maybe somebody will come up a really complex way to do this in one step.&amp;nbsp; But I would use separate steps, first computing row totals:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
   set have;
   array col {3:8} cat3-cat8;
   row_total=0;
   do _n_=3 to 7;
      row_total + num_rat * (col{_n_} + col{_n_ + 1});
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have the total totals completed in this fashion, the rest of the problem should be relatively easy.&amp;nbsp; (If it's not easy, you might have to explain more about what needs to happen at that point.)&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 19:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681739#M206254</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-09-04T19:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681740#M206255</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/345101"&gt;@Jass_Banga&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks Paige, but I think this is not the required answer. I expect the do loop to run through each variable (columns) and calculate the function. Also I intend to minimize the function to one variable (lets say a z_score which can be said to (0 + -1.78)*1885*Z + (-1.78 + -2.68)*1885 *Z + (-2.68 + -3.06)*1885*Z + (-3.06 + -3.4)*1885*Z + (-3.4 + -3.83)*1885*Z.&lt;BR /&gt;&lt;BR /&gt;Sorry I should have mentioned "Z" in my original post.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is no Z in your data set, however the way you have written the modification, you would simply use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;row_sum=(cat3+cat8+2*sum(of cat4-cat7))*num_rat*z;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Sep 2020 19:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681740#M206255</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-04T19:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681750#M206257</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/345101"&gt;@Jass_Banga&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I understand Brad, and apologize for not being clear earlier.&lt;/P&gt;
&lt;P&gt;Below is the equation I need Minimize:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jass_Banga_0-1599247701338.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49027i68E397D69977A21B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jass_Banga_0-1599247701338.png" alt="Jass_Banga_0-1599247701338.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;where&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jass_Banga_1-1599247740442.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49028i33CCC6579ED88A98/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jass_Banga_1-1599247740442.png" alt="Jass_Banga_1-1599247740442.png" /&gt;&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jass_Banga_2-1599247801377.png" style="width: 239px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49029iB2D8D162BF28E489/image-dimensions/239x60?v=v2" width="239" height="60" role="button" title="Jass_Banga_2-1599247801377.png" alt="Jass_Banga_2-1599247801377.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The matrix is&amp;nbsp;data test ;&lt;/P&gt;
&lt;P&gt;data test ;&lt;BR /&gt;input cat $ cat3 cat4 cat5 cat6 cat7 cat8 ;&lt;BR /&gt;cards;&lt;BR /&gt;cat3 0 -1.78 -2.68 -3.06 -3.4 -3.83&lt;BR /&gt;cat4 0 2.12 -2.15 -2.63 -2.94 -3.34&lt;BR /&gt;cat5 0 2.45 1.16 -1.39 -1.99 -2.54&lt;BR /&gt;cat6 0 2.48 1.92 1.19 -1.13 -2.39&lt;BR /&gt;cat7 0 2.68 2.32 1.82 1.52 -1.56&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%let rho = 0.8; *It will be changed after every run*;&lt;BR /&gt;%let z= 0.89; * It should be minimized*;&lt;/P&gt;
&lt;P&gt;DATA TEST1;&lt;BR /&gt;SET test;&lt;BR /&gt;Array Cat_C(6) cat3-cat8;&lt;BR /&gt;Array Cat_g(5) catg3-catg7;&lt;BR /&gt;do i= 1to 5;&lt;BR /&gt;cat_g(i)= num_rat * ((((CDF('Normal', Cat_C(i+1))-CDF('NORMAL',Cat_C(i))-&lt;BR /&gt;((CDF('NORMAL', ((Cat_C(i+1) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))-(CDF ('NORMAL', ((Cat_C(i) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))))**2))/&lt;BR /&gt;(((CDF('NORMAL', ((Cat_C(i+1) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))-(CDF ('NORMAL', ((Cat_C(i) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho)))))*&lt;BR /&gt;(1-((CDF('NORMAL', ((Cat_C(i+1) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))-(CDF ('NORMAL', ((Cat_C(i) - (sqrt(&amp;amp;rho)*&amp;amp;z))/sqrt(1-&amp;amp;rho))))))));&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where x(g+1) is the movement from cat3 to cat4. and rho needs to be any fixed number (say 0.8) and z needs to be minimized using any initial number (say 0.89).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope it helps.&lt;/P&gt;
&lt;P&gt;Thanks again.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you provide a link to where that equation comes from? Minimizing a function like that sure smells related to some form of least squares regression.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 20:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681750#M206257</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-04T20:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681756#M206260</link>
      <description>&lt;A href="https://www.z-riskengine.com/media/1032/a-one-parameter-representation-of-credit-risk-and-transition-matrices.pdf" target="_blank"&gt;https://www.z-riskengine.com/media/1032/a-one-parameter-representation-of-credit-risk-and-transition-matrices.pdf&lt;/A&gt;</description>
      <pubDate>Fri, 04 Sep 2020 20:53:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681756#M206260</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-04T20:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681805#M206281</link>
      <description>&lt;P&gt;Do you have IML or OR ?&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; might give you a hand .&lt;/P&gt;</description>
      <pubDate>Sat, 05 Sep 2020 12:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/681805#M206281</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-05T12:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682429#M206563</link>
      <description>&lt;P&gt;The following PROC OPTMODEL code matches your results for fixed Z = 0.89:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set ROWS;
   num jmax = 6;
   set COLS = 1..jmax;
   num cat_c {ROWS, COLS};
   num num_rat {ROWS};
   read data test into ROWS=[_N_] {j in COLS} &amp;lt;cat_c[_N_,j]=col('cat'||j+2)&amp;gt; num_rat;
   print cat_c;

   var Z init 0.89;

   impvar P {i in ROWS, j in COLS diff {jmax}} = CDF('Normal', Cat_C[i,j+1]) - CDF('NORMAL', Cat_C[i,j]);
   impvar Phi {i in ROWS, j in COLS} = CDF('Normal', (Cat_C[i,j]-sqrt(&amp;amp;rho)*Z)/sqrt(1-&amp;amp;rho));
   impvar Delta {i in ROWS, j in COLS diff {jmax}} = Phi[i,j+1] - Phi[i,j];

   impvar ObjectiveSummand {i in ROWS, j in COLS diff {jmax}} = (num_rat[i] * (P[i,j] - Delta[i,j])**2 / (Delta[i,j] * (1 - Delta[i,j])));
   min Objective = sum {i in ROWS, j in COLS diff {jmax}} ObjectiveSummand[i,j];

   fix Z;
   solve;
   print Objective Z;
   print P Phi Delta;
   print ObjectiveSummand;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Uncomment the FIX statement to let the solver find Z.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 22:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682429#M206563</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-09-08T22:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682455#M206568</link>
      <description>&lt;P&gt;Thanks Rob, you are a genius. your solution works nicely.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one problem, if I don't have proc optmodel in my SAS Enterprise guide, what other options can be used to perform the same function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Jass&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 00:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682455#M206568</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-09T00:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682460#M206569</link>
      <description>&lt;P&gt;I have IML.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 00:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682460#M206569</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-09T00:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682579#M206615</link>
      <description>Try free version SAS.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://welcome.oda.sas.com/login" target="_blank"&gt;https://welcome.oda.sas.com/login&lt;/A&gt;</description>
      <pubDate>Wed, 09 Sep 2020 11:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682579#M206615</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-09T11:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682595#M206625</link>
      <description>&lt;P&gt;Thanks Ksharp. My problem is that if most of my group friends also don't have Proc Optmodel, thats why I would be very thankful if you guys can help me with the code in SAS IML.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jass&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 12:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682595#M206625</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-09T12:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682598#M206626</link>
      <description>&lt;P&gt;Sorry. I have no time. Maybe&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;could write it for you .&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 12:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/682598#M206626</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-09T12:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/683332#M206952</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your code especially Rob. I do not have proc optmodel in my SAS subscription, but I have SAS IML. I have tried to write the code in IML but failed miserably. I tried to read from SAS documentation and online topics and have written the following code. I would be very thankful if you guys can help me fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;x={0 -1.78 -2.68 -3.06 -3.4 -3.83 1885,&lt;BR /&gt;0 2.12 -2.15 -2.63 -2.94 -3.34 3151,&lt;BR /&gt;0 2.45 1.16 -1.39 -1.99 -2.54 246,&lt;BR /&gt;0 2.48 1.92 1.19 -1.13 -2.39 80,&lt;BR /&gt;0 2.68 2.32 1.82 1.52 -1.56 89}&lt;BR /&gt;;&lt;BR /&gt;varNames= ("cat3" : "cat8" ||"num_rat");&lt;BR /&gt;rowNames= ("cat_3" : "cat_7");&lt;BR /&gt;n_x = nrow(x);&lt;BR /&gt;p_x = ncol(x-1);&lt;/P&gt;&lt;P&gt;print n_x p_x ;&lt;/P&gt;&lt;P&gt;create mydata1 from x[colname=varNames rowname=rowNames];&lt;BR /&gt;append from x [rowname = rowNames];&lt;BR /&gt;close mydata1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;start obj_z(p, phi, delta, rho, init_z);&lt;BR /&gt;num_col=ncol(x-1);&lt;BR /&gt;num_row=nrow(x);&lt;BR /&gt;num_r=x[,7];&lt;BR /&gt;do i = 1 to num_row;&lt;BR /&gt;p{i in num_rows, j in num_col} = CDF('Normal', x[i,j+1]) - CDF('NORMAL', x[i,j]);&lt;BR /&gt;phi{i in num_rows, j in num_col} = CDF('Normal', (Cat_C[i,j]-sqrt(&amp;amp;rho)*Z)/sqrt(1-&amp;amp;rho));&lt;BR /&gt;delta {i in num_rows, j in num_col} = Phi[i,j+1] - Phi[i,j];&lt;BR /&gt;sum_z= (num_rat[i] * (P[i,j] - Delta[i,j])**2 / (Delta[i,j] * (1 - Delta[i,j])));&lt;BR /&gt;finish;&lt;BR /&gt;call nlpqn(min(obj_z)) = "result";&lt;BR /&gt;print "result";&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 18:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/683332#M206952</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-11T18:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/684033#M207240</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written the following code but am getting error that&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: (execution) Matrix has not been set to a value&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is given below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;/*start a function to minimized*/&lt;BR /&gt;start obj_z(y) ;&lt;BR /&gt;num_col=ncol(y);&lt;BR /&gt;num_row=nrow(y);&lt;BR /&gt;num_rat=y[,7];&lt;BR /&gt;do i = 1 to num_row;&lt;BR /&gt;do j= 1 to (num_col-2);&lt;BR /&gt;p[i,j] = CDF('Normal', y[i,j+1]) - CDF('NORMAL', y[i,j]);&lt;BR /&gt;phi[i,j] = CDF('Normal', (y[i,j]-sqrt(rho)*Z)/sqrt(1-rho));&lt;BR /&gt;Delta [i,j] = Ph([i,j+1] - Phi[i,j]);&lt;BR /&gt;sum_z= sum((num_r (i)* (P[i,j] - Delta[i,j])**2) / (Delta[i,j] * (1 - Delta[i,j])));&lt;BR /&gt;&lt;BR /&gt;return (sum_z);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;finish obj_z ;&lt;/P&gt;&lt;P&gt;x_1={0 -1.78 -2.68 -3.06 -3.4 -3.83 1885,&lt;BR /&gt;0 2.12 -2.15 -2.63 -2.94 -3.34 3151,&lt;BR /&gt;0 2.45 1.16 -1.39 -1.99 -2.54 246,&lt;BR /&gt;0 2.48 1.92 1.19 -1.13 -2.39 80,&lt;BR /&gt;0 2.68 2.32 1.82 1.52 -1.56 89}&lt;BR /&gt;;&lt;BR /&gt;num_row_1 = nrow(x_1);&lt;BR /&gt;num_col_1 = ncol(x_1);&lt;/P&gt;&lt;P&gt;/*print n_x p_x ;*/&lt;BR /&gt;varNames= ("cat3" : "cat8" || "num_rat");&lt;BR /&gt;rowNames= ("cat3" : "cat7");&lt;/P&gt;&lt;P&gt;create y from x_1[colname=varNames rowname=rowNames];&lt;BR /&gt;append from x_1 [rowname = rowNames];&lt;BR /&gt;/*close x_1;*/&lt;/P&gt;&lt;P&gt;start_z= {0.89}; /*initialize z*/&lt;BR /&gt;rho={0.8}; /* rho is a constant*/&lt;BR /&gt;OPTN= {0 2}; /* options for minimimization problem and result output*/&lt;BR /&gt;call NLPTR(xres, rc, "obj_z",start_z , OPTN) ; /* calling the function*/&lt;BR /&gt;/*print "result";*/&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 19:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/684033#M207240</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-15T19:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/684169#M207304</link>
      <description>Delta [i,j] = Ph([i,j+1] - Phi[i,j]);&lt;BR /&gt;&lt;BR /&gt;In IML, don't have function Ph( ) .</description>
      <pubDate>Wed, 16 Sep 2020 11:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/684169#M207304</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-16T11:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: First loop through columns and then loop through through rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/684341#M207368</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;, now the error is&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: (execution) Invalid subscript or subscript out of range.&lt;/P&gt;&lt;P&gt;Additionally, how can change the IML code to caculate z value for each observation (more like the IML equivalent of "diff" command in OPTMODEL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 18:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-loop-through-columns-and-then-loop-through-through-rows/m-p/684341#M207368</guid>
      <dc:creator>Jass_Banga</dc:creator>
      <dc:date>2020-09-16T18:45:05Z</dc:date>
    </item>
  </channel>
</rss>

