<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Philihp.com &#187; For loops</title>
	<atom:link href="http://www.philihp.com/blog/tag/for-loops/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.philihp.com/blog</link>
	<description>Yes, it's a palindrome.</description>
	<lastBuildDate>Tue, 31 Aug 2010 19:40:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>For loops in SAS</title>
		<link>http://www.philihp.com/blog/2009/for-loops-in-sas/</link>
		<comments>http://www.philihp.com/blog/2009/for-loops-in-sas/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 16:06:22 +0000</pubDate>
		<dc:creator>philihp</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[For loops]]></category>
		<category><![CDATA[List iteration]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[SAS]]></category>

		<guid isPermaLink="false">http://www.philihp.com/blog/?p=490</guid>
		<description><![CDATA[When coding for loops in SAS, one neat thing to remember is that all of the parts of it are optional.
start &#60;TO stop&#62; &#60;BY increment&#62; &#60;WHILE(expression) &#124; UNTIL(expression)&#62;
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000201276.htm
So in another language, what might be
for(int i=0;i < max;i++) {
In SAS, you can leave out the "by 1", since it's the default increment. So this would be
do [...]]]></description>
			<content:encoded><![CDATA[<p>When coding for loops in SAS, one neat thing to remember is that all of the parts of it are optional.</p>
<blockquote><p>start &lt;TO stop&gt; &lt;BY increment&gt; &lt;WHILE(expression) | UNTIL(expression)&gt;</p>
<p><a href="http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000201276.htm"><cite>http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000201276.htm</cite></a></p></blockquote>
<p>So in another language, what might be</p>
<pre>for(int i=0;i < max;i++) {</pre>
<p>In SAS, you can leave out the "by 1", since it's the default increment. So this would be</p>
<pre>do i=0 to max;</pre>
<p>What's fun is in SAS you can combine a <a href="http://en.wikipedia.org/wiki/Do_while_loop">Repeat-Until/Do-While</a> loop with a for loop. This might be useful if for some reason you don't set the var "max" until you've iterated through the loop once, such as in this case, where "<a href="http://support.sas.com/documentation/cdl/en/lrmeta/60739/HTML/default/getnobj.htm">metadata_getnobj</a>" returns a negative on fail, but otherwise returns the number of objects that match the query.</p>
<pre>do i=1 by 1 until (i >= objs);
  rc=metadata_getnobj("omsobj:SASLibrary?@Libref='MYLIBREF'",i,uri);
  if rc>=0 then objs=rc;

  rc=metadata_getnasn(uri,"LibraryConnection",1,uri);
  if rc>=0 then leave;
end;</pre>
<p>This code loops through all the libraries in the metadata with libref='MYLIBREF', and exits with a URI for the first one it sees with at least one LibraryConnection association. This is useful when you have a remote library pointing to a local library and they both have the same name and you want a URI to the remote one.</p>
<p>Another cool thing with FOR loops in SAS is iteration through lists. In Java, say you have a block like this:</p>
<pre>for(String x : new String[] { "a","b","c" }) {
  System.out.println("x="+x);
}</pre>
<p>In SAS, this is simply</p>
<pre>do x="a","b","c";
  put x=;
end;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.philihp.com/blog/2009/for-loops-in-sas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
