<?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 UNTIL Loop with conditional stop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428167#M105685</link>
    <description>&lt;P&gt;Oops, i missed to change this&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%until&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;stop &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%until&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&amp;amp;&lt;/SPAN&gt;stop &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2018 21:10:06 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-01-16T21:10:06Z</dc:date>
    <item>
      <title>Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428147#M105677</link>
      <description>&lt;P&gt;Hello, I wish to use a do until loop until the condition that there is a unique drug for each observation with some form of randomization for 3 repetitions is met.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data units;
do Unit = 1 to 8;
	output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The top shows dummy data. I will explain the overall problem that I have and how I'm trying to solve it.&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-main"&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;&lt;DIV class="lia-message-body lia-component-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drug_1 Drug_2 Drug_3&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the second-fourth column, 1 shows up 2 times, 2 shows up 2 times, 3 shows up 2 times, and 4 shows up 2 times. They also do not repeat through each observation. In this example, the groups (1-4) are evenly distributed but I'd like to have the option to change their sizes depending on the condition&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;To solve this, I am trying to cycle through different seeds to be able to get the desired outcome. To accomplish this, I created two local macros. n is to cycle through seed numbers and stop is to indicate when I've obtained the desired dataset. This outcome is shown through the sum of indicator being 0 or through drug 1 - drug 3 not equal to one another.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m(start);

	%local n;
	%let n=&amp;amp;start;

	%local stop;
	%let stop = 0;

	%do %until(stop ne 0);

			proc surveyselect data=units groups=(2,2,2,2) seed=&amp;amp;n reps=3 noprint
			    out=assignedUnits(rename=groupId=drug); 
			run;

			proc sort data=assignedUnits;
				by Unit;
			run;

			proc transpose data=assignedUnits out=wide1(drop=_NAME_ _LABEL_) prefix=drug_;
			    by Unit;
			    var drug;
			run;

			data desiredData;
				set wide1;
				
				indicator=.;				
				if drug_1 ne drug_2 and drug_1 ne drug_3 and drug_2 ne drug_3 then drug = 0;
					else indicator=1;
				
				st=.;
				if drug_1 ne drug_2 and drug_1 ne drug_3 and drug_2 ne drug_3 then st = 0;
					else %let stop=%eval(&amp;amp;stop+1);
			run;

			proc print data=desiredData;
				sum indicator;
				title "Seed number &amp;amp;n";
			run;

		%let n=%eval(&amp;amp;n+1);
	%end;
%mend m;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, the second if statement is not working. I want it to change the local variable stop to when the if statement is true but it has not been performing as desired. Is there any way to perform this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 20:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428147#M105677</guid>
      <dc:creator>Learning_S</dc:creator>
      <dc:date>2018-01-16T20:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428156#M105680</link>
      <description>&lt;P&gt;That is because you are trying to execute a macro statement at execution time(datastep execution). Unfortunately, that execution&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; stop&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%eval&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;stop&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;happens at compile time.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 20:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428156#M105680</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-16T20:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428158#M105682</link>
      <description>&lt;P&gt;I can't promise this fixes everything, but here are two items that must be changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do %until (stop ne 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This comparison will always be true, because STOP does not refer to a DATA step variable named STOP.&amp;nbsp; Instead, you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do %until (&amp;amp;stop = 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, the DATA step cannot execute a %LET statement.&amp;nbsp; This statement is not doing anything when the DATA step executes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else %let stop = %eval(&amp;amp;stop + 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This might be closer to what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else call symputx('stop', '1');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would assign the macro variable &amp;amp;STOP a value of 1, when the ELSE statement executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be more, but fixing this would at least be a starting point.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 20:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428158#M105682</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-16T20:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428161#M105683</link>
      <description>&lt;P&gt;i tried to fix a bit, see if this helps:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m(start);

	%local n;
	%let n=&amp;amp;start;

	%local stop;
	%let stop = 0;

	%do %until(stop ne 0);

			proc surveyselect data=units groups=(2,2,2,2) seed=&amp;amp;n reps=3 noprint
			    out=assignedUnits(rename=groupId=drug); 
			run;

			proc sort data=assignedUnits;
				by Unit;
			run;

			proc transpose data=assignedUnits out=wide1(drop=_NAME_ _LABEL_) prefix=drug_;
			    by Unit;
			    var drug;
			run;

			data desiredData;
				set wide1;
				
				indicator=.;	
				st=.;
				if (drug_1 ne drug_2) and (drug_1 ne drug_3) and (drug_2 ne drug_3) then do;
					drug = 0;
					st = 0;
					end;
					else do; 
					indicator=1;
					call symputX('stop',resolve('&amp;amp;stop')+1);
					end;
				
				
			run;

			proc print data=desiredData;
				sum indicator;
				title "Seed number &amp;amp;n";
			run;

		%let n=%eval(&amp;amp;n+1);
	%end;
%mend m;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 20:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428161#M105683</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-16T20:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428166#M105684</link>
      <description>&lt;P&gt;Thanks, that almost works. Unfortunately, it continues past seed 93 (I verified that it meets the aforementioned conditions). I read that symputX converts it to character. Am I correct in that assertion as could that be why it keeps going?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 21:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428166#M105684</guid>
      <dc:creator>Learning_S</dc:creator>
      <dc:date>2018-01-16T21:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428167#M105685</link>
      <description>&lt;P&gt;Oops, i missed to change this&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%until&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;stop &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%until&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&amp;amp;&lt;/SPAN&gt;stop &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 21:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428167#M105685</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-16T21:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428174#M105688</link>
      <description>&lt;P&gt;I apologize, but I saw a major error in my program. The symputX('stop',resolve('&amp;amp;stop')+1); portion should somehow be related to the sum of the indicator variable. Would the following work?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if sum(indicator) = 0 then call symputX('stop',resolve('&amp;amp;stop')+1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 21:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428174#M105688</guid>
      <dc:creator>Learning_S</dc:creator>
      <dc:date>2018-01-16T21:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Do UNTIL Loop with conditional stop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428179#M105689</link>
      <description>&lt;P&gt;Nope, won't work. If i can guess, You may have to change the part of the&amp;nbsp; program to this :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data desiredData;
				set wide1 end=last;
				
				indicator=.;	
				st=.;
				if (drug_1 ne drug_2) and (drug_1 ne drug_3) and (drug_2 ne drug_3) then do;
					drug = 0;
					st = 0;
					end;
					else do; 
					indicator=1;
					end;
				sum_indicator+indicator;
      if last then do; if sum_indicator=0 then /*your call symputx goes here*/
				
			run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 21:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-UNTIL-Loop-with-conditional-stop/m-p/428179#M105689</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-16T21:35:25Z</dc:date>
    </item>
  </channel>
</rss>

