<?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: Do loop in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317977#M61826</link>
    <description>&lt;P&gt;&amp;nbsp;Thank you so much, this idea should work... I'm very new in SAS, sorry for asking basic questions...&amp;nbsp;what value then I need to use&amp;nbsp;to start from the beginning when it ends reading the file?&lt;/P&gt;</description>
    <pubDate>Fri, 09 Dec 2016 19:42:34 GMT</pubDate>
    <dc:creator>Mina-sh</dc:creator>
    <dc:date>2016-12-09T19:42:34Z</dc:date>
    <item>
      <title>Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317643#M61794</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm using SAS 9.3.1 and I am trying to assign the values of a variable (demand) from a file (a) to a&amp;nbsp;new set of variables using do loops. The problem is that the file 'a' has 5 observations and therefore after the first execution it reads all the data perfectly. But for the second round (i=2) it cannot perform the same task and start reading the file 'a' just like the previous&amp;nbsp;iteration. It is like when a file is read once cannot be read for the second time. As the result, I don't have the desired outputs for the second run. Please note that the program executes without showing any error. &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm forwarding you the whole file in which you can find this specific part with all data example I'm using.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do appreciate your time helping me&amp;nbsp;to find out the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Mina&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i=1 to 2;&lt;BR /&gt;_type_='GE';&lt;BR /&gt;_row_='Res_P'||put(i,1.);&lt;BR /&gt;_col_='_RHS_';&lt;BR /&gt;_coef_=0;&lt;BR /&gt;output;&lt;BR /&gt;_type_=' ';&lt;BR /&gt;do k=1 to 4;&lt;BR /&gt;_col_='Y'||put(i,1.)||put(k,1.);&lt;BR /&gt;_coef_=1.0;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;do h=1 to 5;&lt;BR /&gt;set a;&lt;BR /&gt;_col_='Z'||put(i,1.)||put(h,1.);&lt;BR /&gt;_coef_=1.0;&lt;BR /&gt;output;&lt;BR /&gt;_col_='S'||put(i,1.)||put(h,1.);&lt;BR /&gt;_coef_=-demand;&lt;BR /&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;end;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 16:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317643#M61794</guid>
      <dc:creator>Mina-sh</dc:creator>
      <dc:date>2016-12-08T16:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317649#M61796</link>
      <description>&lt;P&gt;The solution is simple (I think!), but comes with a warning.&amp;nbsp; Change the SET statement to become:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set a point=h;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;POINT= tells the software which observation to bring in, but allows for moving back to the beginning and starting over again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The warning:&amp;nbsp; by doing this, you may create an infinite loop.&amp;nbsp; While you haven't posted the entire DATA step, so it's impossible to be certain, you will likely need to add a STOP statement at the bottom of the DATA step to make sure it ends.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 16:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317649#M61796</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-08T16:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317652#M61797</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, firstly the code you give is very confusing. &amp;nbsp;It is really not a good idea to call your variables _xyz_ as these types of things are reserved for SAS core functionality. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now looking at the output, it all seems a bit overcomplicated - there is lots being created here for no apparent reason or logic, therefore any work you do further on this data will be far harder. &amp;nbsp;I am presuming its for a report? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, as the basis is demand, and you create a bunch of observations for each obs in demand, set that as your base loop:&lt;/P&gt;
&lt;PRE&gt;data modified;
  set demand;
  _row_=cats("Res_P",put(customer,best.));
  _col_="_RHS_";
  _coef_=0;
  output;
  do i=10 to 14;
    _col_=cats("Y",put(i,best.));
    _coef_=1;
    output;
  end;
  do i=11 to 15;
    _col_=cats("Z",put(i,best));
    _coef_=...;
    output;
    _col_=cats("S",put(i,best.));
    _coef_=...;
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Here, instead of doing some creation, then later setting the data in a loop, I use the demand dataset and for each observation output a bunch of rows. &amp;nbsp;Seems simpler to me, but then as I say the whole structure and purpose of this output is a total mystery to my, or why you would want to do things in this manner?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 16:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317652#M61797</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-08T16:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317977#M61826</link>
      <description>&lt;P&gt;&amp;nbsp;Thank you so much, this idea should work... I'm very new in SAS, sorry for asking basic questions...&amp;nbsp;what value then I need to use&amp;nbsp;to start from the beginning when it ends reading the file?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 19:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317977#M61826</guid>
      <dc:creator>Mina-sh</dc:creator>
      <dc:date>2016-12-09T19:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317981#M61827</link>
      <description>&lt;P&gt;Thank you so much. You are right, this structure is&amp;nbsp;weird and I don't like it either, but I have to adhere to that to prepare my data for the proc lp&amp;nbsp;(for SAS OR)... I cannot change the counter because I need to write it there...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 19:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317981#M61827</guid>
      <dc:creator>Mina-sh</dc:creator>
      <dc:date>2016-12-09T19:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317998#M61828</link>
      <description>&lt;P&gt;You may want to consider using some of the concatenation functions. In stead of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_col_='Z'||put(i,1.)||put(h,1.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;could use&lt;/P&gt;
&lt;P&gt;_col_ = cats('Z',i,h);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CATS removes leading and trailing blanks. The || put(var, format.) will often have either leading or trailing blanks..&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 20:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317998#M61828</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-09T20:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317999#M61829</link>
      <description>&lt;P&gt;The interior DO loop uses:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do h=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this automatically starts from the beginning because it uses H to choose which observation to read:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set have point=H;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 20:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/317999#M61829</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-09T20:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/318007#M61830</link>
      <description>&lt;P&gt;I do appreciate you. I added the point=H to the set statement as an option:&lt;/P&gt;&lt;P&gt;set a point=H;&lt;/P&gt;&lt;P&gt;But it seems like I got stuck in a loop... should I add/change something else? This way it doesn't work...&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 23:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/318007#M61830</guid>
      <dc:creator>Mina-sh</dc:creator>
      <dc:date>2016-12-09T23:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/318008#M61831</link>
      <description>&lt;P&gt;Oh! thank you so much for giving me this point. This will be really helpful.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 23:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/318008#M61831</guid>
      <dc:creator>Mina-sh</dc:creator>
      <dc:date>2016-12-09T23:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/318012#M61832</link>
      <description>&lt;P&gt;Yes. &amp;nbsp;When using point=, there often is no ending to the DATA step. &amp;nbsp;You have to add your own ending by adding a STOP statement. &amp;nbsp;I thought I pointed this out in my original response, but it's probably a lot to absorb at one time. &amp;nbsp;Nothing like experience to ingrain the knowledge though.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2016 00:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop/m-p/318012#M61832</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-10T00:31:34Z</dc:date>
    </item>
  </channel>
</rss>

