<?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: Repeat codes following a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94521#M19949</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, it would be safer to force termination of the loop after a certain number of iterations, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to 100 until(MUNIC2 ne MUNIC);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w= rand...;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1&amp;lt;w&amp;lt;2 then MUNIC2 = 3;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;just in case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PG&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 09 Dec 2012 00:27:28 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2012-12-09T00:27:28Z</dc:date>
    <item>
      <title>Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94511#M19939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a variable X with 10 categories (1, 2, 3,...10). The data set has 5000 lines. I want to create a variable Y in which the category of some of them would have to change to another following an equation. I have no problem until here. My problem is that if the category at Y is the same as the category at X, I want to repeat the operation and I don't know how.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I.E.&lt;/P&gt;&lt;P&gt;Suppose that X=5.&lt;/P&gt;&lt;P&gt;If "condition is respected" then Y = "equation attributing a number between 1 and 10".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is no problem if the category for Y is anything else than 5. However, if it's 5, I need to repeat the "if" statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 22:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94511#M19939</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2012-12-08T22:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94512#M19940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;are you looking for something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if y=5 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ???&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ???&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 22:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94512#M19940</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-12-08T22:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94513#M19941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course, this code works for one time, but if Y is still 5 after the second repetition, the problem is still present. I guess I could just repeat "if y=5 then do" like 10 times, but it's not really elegant.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 22:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94513#M19941</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2012-12-08T22:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94514#M19942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you could put your if statement in a macro, below is an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;age=age+5;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if age=14 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %test&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc print;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 23:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94514#M19942</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-12-08T23:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94515#M19943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Post some sample data and desired results from that data.&amp;nbsp; Posting the code that you've tried wouldn't hurt either.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 23:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94515#M19943</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-08T23:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94516#M19944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Linlin Same problem as the previous. The macro is only launch one time, so if age is still 14 after running it (well... it's impossible in your example, but it is in mine), it will remain 14.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 23:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94516#M19944</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2012-12-08T23:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94517#M19945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand you problem now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 23:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94517#M19945</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-12-08T23:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94518#M19946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is a variable MUNIC whose categories are 1-2-3-4-5-6-7-9-10 (there is no 8).&lt;/P&gt;&lt;P&gt;The variable MUNIC2 would be created according to those statements:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;w=rand('uniform');&lt;/P&gt;&lt;P&gt;if banlieue=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if w&amp;lt;probbbm1 then MUNIC2=1; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm1&amp;lt;=w&amp;lt;probbbm2 then MUNIC2=2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm2&amp;lt;=w&amp;lt;probbbm3 then MUNIC2=3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm3&amp;lt;=w&amp;lt;probbbm4 then MUNIC2=4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm4&amp;lt;=w&amp;lt;probbbm5 then MUNIC2=5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm5&amp;lt;=w&amp;lt;probbbm6 then MUNIC2=6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm6&amp;lt;=w&amp;lt;probbbm7 then MUNIC2=7;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm7&amp;lt;=w&amp;lt;probbbm9 then MUNIC2=9;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if probbbm9&amp;lt;=w&amp;lt;probbbm10 then MUNIC2=10;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus, I want another condition saying that if MUNIC2=MUNIC then I repeat the creation of MUNIC2 until MUNIC2 /= MUNIC.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 23:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94518#M19946</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2012-12-08T23:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94519#M19947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have almost spelled out the solution.&amp;nbsp; SAS supports DO UNTIL, so you could do something along these lines:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if banilieue=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; MUNIC2=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (MUNIC2 &amp;gt;= MUNIC);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MUNIC2 = MUNIC2 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if MUNIC2=8 then MUNIC2=9;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This might not be exactly what you want in terms of results, but it should be the right set of tools to apply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Dec 2012 00:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94519#M19947</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-12-09T00:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94520#M19948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems like you want something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do until(MUNIC2 ne MUNIC);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w= rand...;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1&amp;lt;w&amp;lt;2 then MUNIC2 = 3;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;be careful not to create an infinite loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Dec 2012 00:20:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94520#M19948</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-12-09T00:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94521#M19949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, it would be safer to force termination of the loop after a certain number of iterations, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to 100 until(MUNIC2 ne MUNIC);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w= rand...;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 1&amp;lt;w&amp;lt;2 then MUNIC2 = 3;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;just in case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PG&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Dec 2012 00:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94521#M19949</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-12-09T00:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat codes following a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94522#M19950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I didn't know that SAS supports DO UNTIL. Problem solved.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Dec 2012 00:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-codes-following-a-condition/m-p/94522#M19950</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2012-12-09T00:30:41Z</dc:date>
    </item>
  </channel>
</rss>

