<?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 Generating lags of multiple variables at once in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131611#M35772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&amp;nbsp; I have a question which I'm sure is very easy, but I'm stumped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I generate lags of multiple variables at once?&amp;nbsp; I have 105 variables -- each variable I need to lag once and twice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've created an array, and tried a number of DO statements, but nothing seems to work.&amp;nbsp; Anyone have any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 May 2013 16:40:22 GMT</pubDate>
    <dc:creator>TalonHill</dc:creator>
    <dc:date>2013-05-07T16:40:22Z</dc:date>
    <item>
      <title>Generating lags of multiple variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131611#M35772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&amp;nbsp; I have a question which I'm sure is very easy, but I'm stumped.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I generate lags of multiple variables at once?&amp;nbsp; I have 105 variables -- each variable I need to lag once and twice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've created an array, and tried a number of DO statements, but nothing seems to work.&amp;nbsp; Anyone have any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 16:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131611#M35772</guid>
      <dc:creator>TalonHill</dc:creator>
      <dc:date>2013-05-07T16:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Generating lags of multiple variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131612#M35773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like this could work. But you have to be careful with you first.&lt;EM&gt;&lt;STRONG&gt;keyword&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt; to reset all the lag values to .&lt;/STRONG&gt; so it doesn't carry over the value from prior record...&lt;/P&gt;&lt;P&gt;but this piece of code should get you started:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select cat("prev_",name,"= lag(",name,");") into: my_list separated by " "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname = "&lt;STRONG&gt;SASHELP&lt;/STRONG&gt;" &amp;amp; memname = "&lt;STRONG&gt;CLASS&lt;/STRONG&gt;" ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &lt;STRONG&gt;sashelp.class;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;my_list.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;All you need to change is the name of your library (WORK?) and the name of the dataset. Make sure you use CAPS.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anca&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 18:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131612#M35773</guid>
      <dc:creator>AncaTilea</dc:creator>
      <dc:date>2013-05-07T18:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Generating lags of multiple variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131613#M35774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;array vars &amp;lt;your list of vars here&amp;gt;;&lt;/P&gt;&lt;P&gt;array L1vars &amp;lt;your list of vars prefixed with L1 here&amp;gt;;&lt;/P&gt;&lt;P&gt;array L2vars &amp;lt;your list of vars prefixed with L2 here&amp;gt;;&lt;/P&gt;&lt;P&gt;Do i = 1 to dim(vars);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; L1Vars&lt;I&gt; = lag(vars&lt;I&gt;);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; L2Vars&lt;I&gt; = lag2(vars&lt;I&gt;);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;should work unless you make the do loop conditional.&lt;/P&gt;&lt;P&gt;The LAG2 variables will be blank for the first two records and the Lag variables blank on the first record.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 22:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131613#M35774</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-05-07T22:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Generating lags of multiple variables at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131614#M35775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tow optional ways :&lt;/P&gt;&lt;P&gt;set x point=_n_-1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HashTable&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2013 14:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Generating-lags-of-multiple-variables-at-once/m-p/131614#M35775</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-05-08T14:18:07Z</dc:date>
    </item>
  </channel>
</rss>

