<?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: Variable do loop conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-do-loop-conditions/m-p/839315#M331867</link>
    <description>&lt;P&gt;This seems to be part of a bigger problem, am I right? What are you trying to accomplish?&lt;/P&gt;</description>
    <pubDate>Wed, 19 Oct 2022 09:47:23 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-10-19T09:47:23Z</dc:date>
    <item>
      <title>Variable do loop conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-do-loop-conditions/m-p/839313#M331866</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write a program which will loop over an observation for a varying number of times, depending on the contents of this observation. So something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data variable_length_loop;
	set sashelp.cars;

	if Origin EQ "Asia" then
		do i = 1, 2;
	else if Origin EQ "Europe" then
		do i = 3;
			Origin_short = substr(Origin, 1, i);
			output;
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can obviously get it to work by repeating the code block between do and end:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data variable_length_loop;
	set sashelp.cars;

	if Origin EQ "Asia" then
		do i = 1, 2;
			Origin_short = substr(Origin, 1, i);
			output;
		end;
	else if Origin EQ "Europe" then
		do i = 3;
			Origin_short = substr(Origin, 1, i);
			output;
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is that this leads to a lot of copypasting with increased complexity of the code and the number of the conditions to cover. Is this possible without resorting to macros? Thank you for your feedback in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 08:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-do-loop-conditions/m-p/839313#M331866</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-10-19T08:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Variable do loop conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-do-loop-conditions/m-p/839315#M331867</link>
      <description>&lt;P&gt;This seems to be part of a bigger problem, am I right? What are you trying to accomplish?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 09:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-do-loop-conditions/m-p/839315#M331867</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-19T09:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Variable do loop conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-do-loop-conditions/m-p/839334#M331879</link>
      <description>&lt;P&gt;I am trying to calculate frequencies of events. The denominator varies, and some frequencies need to be calculated for more than one denominator. I guess I could just calculate all combinations and filter the ones I don't need out, but this seems rather wasteful.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 10:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-do-loop-conditions/m-p/839334#M331879</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-10-19T10:49:02Z</dc:date>
    </item>
  </channel>
</rss>

