<?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: ERROR: The %DO statement is not valid in open code. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143458#M261732</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, for a longer explanation of what LinusH posted, please see my paper "Macro Basics for New SAS Users". If you are struggling with the correct usage for %DO, it is possible that the paper will explain that in more detail and, the rest of the paper might be useful too.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/120-2013.pdf" title="http://support.sas.com/resources/papers/proceedings13/120-2013.pdf"&gt;http://support.sas.com/resources/papers/proceedings13/120-2013.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jan 2014 17:41:18 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2014-01-16T17:41:18Z</dc:date>
    <item>
      <title>ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143456#M261730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, How can I fix this by maintaining&amp;nbsp; %do u=1 %to 20;&amp;nbsp; .........%end&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set new;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do u=1 %to 20;&amp;nbsp; &lt;/P&gt;&lt;P&gt;proc surveyselect data=new&amp;nbsp; method = urs sampsize = 141 OUTHITS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reps=1 seed=1234100 out=new_&amp;amp;u;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: The %DO statement is not valid in open code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CODES..........&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 17:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143456#M261730</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2014-01-16T17:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143457#M261731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By having it in closed code (that is, wrap it into a macro definition).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 17:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143457#M261731</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-01-16T17:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143458#M261732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, for a longer explanation of what LinusH posted, please see my paper "Macro Basics for New SAS Users". If you are struggling with the correct usage for %DO, it is possible that the paper will explain that in more detail and, the rest of the paper might be useful too.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/120-2013.pdf" title="http://support.sas.com/resources/papers/proceedings13/120-2013.pdf"&gt;http://support.sas.com/resources/papers/proceedings13/120-2013.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 17:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143458#M261732</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2014-01-16T17:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143459#M261733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SURVERSELECT has features that should eliminate the need to MACRO look it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 17:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143459#M261733</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2014-01-16T17:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143460#M261734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I put it in a macro it runs but no data is created. The data set test is real data that I want to do random sample with replacement. I can not use the option in proc surveyselec that does not require macro because of some computations that were performed in the code&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data test;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set test;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%MACRO DO_BRANCH; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%do u=1 %to 20; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc surveyselect data=test&amp;nbsp; method = urs sampsize = 141 OUTHITS&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reps=1 seed=1234100 out=new_&amp;amp;u;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;ERROR: The %DO statement is not valid in open code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;CODES..........&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%MEND DO_BRANCH; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 18:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143460#M261734</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2014-01-16T18:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143461#M261735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think what you need to do is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%MACRO DO_BRANCH; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%do u=1 %to 20; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc surveyselect data=test&amp;nbsp; method = urs sampsize = 141 OUTHITS&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reps=1 seed=1234100 out=new_&amp;amp;u;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;CODES.....&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; %MEND DO_BRANCH; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%DO_BRANCH&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 18:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143461#M261735</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2014-01-16T18:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143462#M261736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks; I ran the code but &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;surveyselect&lt;/SPAN&gt; created just new_1 and no data from new_2 to new_20&lt;/P&gt;&lt;P&gt;I ran the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%MACRO DO_BRANCH;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%do u=1 %to 20;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc surveyselect data=test&amp;nbsp; method = urs sampsize = 141 OUTHITS&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reps=1 seed=1234100 out=new_&amp;amp;u;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;CODES.....&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%MEND DO_BRANCH;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%DO_BRANCH;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 19:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143462#M261736</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2014-01-16T19:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143463#M261737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following code works just fine when testing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO DO_BRANCH;&lt;/P&gt;&lt;P&gt;%do u=1 %to 20;&lt;/P&gt;&lt;P&gt;proc surveyselect data=sashelp.class&amp;nbsp; method = urs sampsize = 14 OUTHITS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reps=1 seed=1234100 out=new_&amp;amp;u;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%MEND DO_BRANCH;&lt;/P&gt;&lt;P&gt;%DO_BRANCH;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, 2 important things to note. Since all procedure resets to the start of the seed, your current implementation would yield new_1=new_2=...=new_20. That is, the exact same 141 records would be selected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect its the part in CODES... that triggers your empty new_2 to new_20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As DN pointed out, a more natural approach would be to use REPS=20 and then split the resulting file BY REPLICATE (the automatically generated variable listing the count of REPS). This would clear your issue with having to change seeds each time as then it keeps on drawing numbers from the same seed rather than reseting at the beginning of the seed for each procedure iteration.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 20:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143463#M261737</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2014-01-16T20:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143464#M261738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you do something in the &lt;EM&gt;CODES...&lt;/EM&gt; part that modifies the output data sets?&lt;/P&gt;&lt;P&gt;when I ran your code like this, it worked:&lt;/P&gt;&lt;P&gt;%MACRO DO_BRANCH;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do u=1 %to &lt;STRONG&gt;4&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;proc surveyselect data=&lt;STRONG&gt;SASHELP.CLASS&lt;/STRONG&gt;&amp;nbsp; method = urs sampsize = 141 OUTHITS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reps=1 seed=1234100 out=new_&amp;amp;u;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/*CODES.....*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%MEND DO_BRANCH;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%DO_BRANCH;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2014 20:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/143464#M261738</guid>
      <dc:creator>AncaTilea</dc:creator>
      <dc:date>2014-01-16T20:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: The %DO statement is not valid in open code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/318282#M261739</link>
      <description>This helped me. Thank you.</description>
      <pubDate>Mon, 12 Dec 2016 15:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-The-DO-statement-is-not-valid-in-open-code/m-p/318282#M261739</guid>
      <dc:creator>sas_pgmr</dc:creator>
      <dc:date>2016-12-12T15:11:22Z</dc:date>
    </item>
  </channel>
</rss>

