<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: SAS lag problems</title>
	<atom:link href="http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/feed/" rel="self" type="application/rss+xml" />
	<link>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/</link>
	<description>I'm a biologist not a...</description>
	<lastBuildDate>Wed, 08 Feb 2012 12:02:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Brittany</title>
		<link>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/comment-page-1/#comment-216798</link>
		<dc:creator>Brittany</dc:creator>
		<pubDate>Fri, 02 Sep 2011 18:46:19 +0000</pubDate>
		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/#comment-216798</guid>
		<description>Thank you for posting this!  Donny &amp; I were struggling over this issue.  You saved us hours!</description>
		<content:encoded><![CDATA[<p>Thank you for posting this!  Donny &amp; I were struggling over this issue.  You saved us hours!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JonathanP</title>
		<link>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/comment-page-1/#comment-201746</link>
		<dc:creator>JonathanP</dc:creator>
		<pubDate>Fri, 17 Jun 2011 19:35:04 +0000</pubDate>
		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/#comment-201746</guid>
		<description>Try something like this:

/************************/
/*YOU NEED BY PROCESSING*/
/************************/

data test;
input id $1 x;
cards;
a 1
a 2
a 3
b 12
b 13
b 15
run;


data test;
  set test;
  by id;
  array AC[*] c;
  c = lag1(x);
  if first.id then count = 1;
  do i = count to dim(ac);
    ac(i) = .;
  end;
  count + 1;
run;

proc sql noprint;

  alter table test drop count, i;

quit;</description>
		<content:encoded><![CDATA[<p>Try something like this:</p>
<p>/************************/<br />
/*YOU NEED BY PROCESSING*/<br />
/************************/</p>
<p>data test;<br />
input id $1 x;<br />
cards;<br />
a 1<br />
a 2<br />
a 3<br />
b 12<br />
b 13<br />
b 15<br />
run;</p>
<p>data test;<br />
  set test;<br />
  by id;<br />
  array AC[*] c;<br />
  c = lag1(x);<br />
  if first.id then count = 1;<br />
  do i = count to dim(ac);<br />
    ac(i) = .;<br />
  end;<br />
  count + 1;<br />
run;</p>
<p>proc sql noprint;</p>
<p>  alter table test drop count, i;</p>
<p>quit;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: VVS</title>
		<link>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/comment-page-1/#comment-198758</link>
		<dc:creator>VVS</dc:creator>
		<pubDate>Thu, 19 May 2011 01:44:35 +0000</pubDate>
		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/#comment-198758</guid>
		<description>I really spent ~2 hours to debug the same type of (buggy) behaviour. The source of such behaviour looks like it creates really 2 separate independent local iterator (and also variable) in every &quot;block&quot; which are inside if ... and else ... statements. The only thing to understood that is to notice the way SAS define their syntax: you should use &quot;do; ... end;&quot; to define solid block of commands inside SAS code, which is very important. Of course, there is no any word about what they mean saying &quot;it is important&quot; and also about if you don&#039;t declare &quot;do; ... end;&quot; it would be declared anyway in &quot;background&quot; :). But really phrase &quot;it is important&quot; means that any variable inside such blocks is local for this block... :(
I think you could use lag() inside if .. else.. if you find the way to declare your variable be global... 

Other idea is that java (in which SAS macrolanguage was written?) is too stupid language which make everything be object even in case of simple macro language translator for if..else.. parsing. So we got separate uncooperative object pieces in SAS from solid code in our mind, guessing then where was the mistake...</description>
		<content:encoded><![CDATA[<p>I really spent ~2 hours to debug the same type of (buggy) behaviour. The source of such behaviour looks like it creates really 2 separate independent local iterator (and also variable) in every &#8220;block&#8221; which are inside if &#8230; and else &#8230; statements. The only thing to understood that is to notice the way SAS define their syntax: you should use &#8220;do; &#8230; end;&#8221; to define solid block of commands inside SAS code, which is very important. Of course, there is no any word about what they mean saying &#8220;it is important&#8221; and also about if you don&#8217;t declare &#8220;do; &#8230; end;&#8221; it would be declared anyway in &#8220;background&#8221; :). But really phrase &#8220;it is important&#8221; means that any variable inside such blocks is local for this block&#8230; :(<br />
I think you could use lag() inside if .. else.. if you find the way to declare your variable be global&#8230; </p>
<p>Other idea is that java (in which SAS macrolanguage was written?) is too stupid language which make everything be object even in case of simple macro language translator for if..else.. parsing. So we got separate uncooperative object pieces in SAS from solid code in our mind, guessing then where was the mistake&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/comment-page-1/#comment-167492</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Thu, 01 Jul 2010 18:53:38 +0000</pubDate>
		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/#comment-167492</guid>
		<description>From what I understand, this is not a bug. Calling lag(x) does two things: (1) it saves the current value of x for the next call of lag(x); and (2) it returns the previously-saved value of x (saved by a prior call to lag(x)).

Here&#039;s someone&#039;s PDF explaining what they call a common misuse of lag():

http://www.nesug.org/proceedings/nesug06/cc/cc32.pdf

It makes sense to me in that &quot;altered way of thinking&quot; that SAS sometimes provokes lol.</description>
		<content:encoded><![CDATA[<p>From what I understand, this is not a bug. Calling lag(x) does two things: (1) it saves the current value of x for the next call of lag(x); and (2) it returns the previously-saved value of x (saved by a prior call to lag(x)).</p>
<p>Here&#8217;s someone&#8217;s PDF explaining what they call a common misuse of lag():</p>
<p><a href="http://www.nesug.org/proceedings/nesug06/cc/cc32.pdf" rel="nofollow">http://www.nesug.org/proceedings/nesug06/cc/cc32.pdf</a></p>
<p>It makes sense to me in that &#8220;altered way of thinking&#8221; that SAS sometimes provokes lol.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ozzy</title>
		<link>http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/comment-page-1/#comment-141299</link>
		<dc:creator>Ozzy</dc:creator>
		<pubDate>Thu, 20 Aug 2009 14:24:42 +0000</pubDate>
		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/programmer/sas-lag-problems/#comment-141299</guid>
		<description>Just saw your post - I had the same problem, but just for the second record where it seemed to go two back.  I tried every trick I could think of, no go.   I simply moved the lag outside the else() statement and into the main body and *viola* worked like a charm.

BTW, a nice write-up and examples of the lag from heck :0)

http://www.howles.com/saspapers/CC33.pdf</description>
		<content:encoded><![CDATA[<p>Just saw your post &#8211; I had the same problem, but just for the second record where it seemed to go two back.  I tried every trick I could think of, no go.   I simply moved the lag outside the else() statement and into the main body and *viola* worked like a charm.</p>
<p>BTW, a nice write-up and examples of the lag from heck :0)</p>
<p><a href="http://www.howles.com/saspapers/CC33.pdf" rel="nofollow">http://www.howles.com/saspapers/CC33.pdf</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

