<?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 Lag variables by group and set all lags to missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Lag-variables-by-group-and-set-all-lags-to-missing/m-p/740253#M231190</link>
    <description>&lt;P&gt;I have this code (don't consider a data snippet necessary in this case, let me know).&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;data temp;
set test;
by id;
lag_1=lag(var1);
lag_2=lag(var2);
lag_3=lag(var3);
lag_4=lag(var4);
lag_5=lag(var5);
if first.id then lag_:=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this and on the last line it gives me an error: "statement is not valid or it is used out of proper order".&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried to do&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.id then lag_1-lag_5=.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it gives me the same error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure this is very stupid, but how can I do it so that I don't have to write all 5 (in reality I have around 60 lagged variables I need to do, hence why I need the short way)?&lt;/P&gt;</description>
    <pubDate>Mon, 10 May 2021 19:33:05 GMT</pubDate>
    <dc:creator>catkat96</dc:creator>
    <dc:date>2021-05-10T19:33:05Z</dc:date>
    <item>
      <title>Lag variables by group and set all lags to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-variables-by-group-and-set-all-lags-to-missing/m-p/740253#M231190</link>
      <description>&lt;P&gt;I have this code (don't consider a data snippet necessary in this case, let me know).&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;data temp;
set test;
by id;
lag_1=lag(var1);
lag_2=lag(var2);
lag_3=lag(var3);
lag_4=lag(var4);
lag_5=lag(var5);
if first.id then lag_:=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this and on the last line it gives me an error: "statement is not valid or it is used out of proper order".&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried to do&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.id then lag_1-lag_5=.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it gives me the same error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure this is very stupid, but how can I do it so that I don't have to write all 5 (in reality I have around 60 lagged variables I need to do, hence why I need the short way)?&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 19:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-variables-by-group-and-set-all-lags-to-missing/m-p/740253#M231190</guid>
      <dc:creator>catkat96</dc:creator>
      <dc:date>2021-05-10T19:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Lag variables by group and set all lags to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-variables-by-group-and-set-all-lags-to-missing/m-p/740257#M231192</link>
      <description>&lt;P&gt;You can use CALL MISSING() to set multiple variables to missing on one function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.id then call missing(of lag_:);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 May 2021 19:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-variables-by-group-and-set-all-lags-to-missing/m-p/740257#M231192</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-10T19:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Lag variables by group and set all lags to missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-variables-by-group-and-set-all-lags-to-missing/m-p/740259#M231194</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CALL MISSING will set a list of variables to missing values.&lt;/P&gt;
&lt;P&gt;Call missing is also one of the few functions that will take both numeric and character variables in a single function call.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if first.id then call missing (lag_1 - lag_5);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general you only get one variable as the target of an = sign.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 19:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-variables-by-group-and-set-all-lags-to-missing/m-p/740259#M231194</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-10T19:50:44Z</dc:date>
    </item>
  </channel>
</rss>

