<?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: LAG function not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896569#M354263</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373742"&gt;@Kaushansky&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;Also what is&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;(drop=total_:);&lt;/LI-CODE&gt;
&lt;P&gt;Meant to do? I took it out since it was giving me an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Patrick had guessed that maybe your dataset&amp;nbsp;&lt;CODE class=" language-sas"&gt;UTP_REDBULL_DF_2&lt;/CODE&gt; already has variables named&amp;nbsp;total_dsp_display_imps etc.&amp;nbsp; Is that correct? If so, you don't want to read them in the DATA step, because they will collide with the variables you are creating in the step as accumulators.&amp;nbsp; Therefore drop= will not read in any variables that start with total_&amp;nbsp; . But if this was throwing an error when you ran it, that suggests these variables don't actually exist in UTP_REDBULL_DF_2. So Patrick's guess as to the cause of the problem may have been wrong, but sounds like the code Patrick wrote is right. : )&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 UTP_REDBULL_DF_3;
  set UTP_REDBULL_DF_2(drop=total_:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 30 Sep 2023 15:26:05 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-09-30T15:26:05Z</dc:date>
    <item>
      <title>LAG function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896524#M354243</link>
      <description>&lt;P&gt;The LAG function is not working for this dataset for the variable&amp;nbsp;&lt;SPAN&gt;dsp_display_prev and&amp;nbsp;dsp_display_cmli_id.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please see the data set attached and here is the code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;proc sort data=UTP_REDBULL_DF_2;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; by luid&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; dsp_display_cmli_id &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; display_cmli_id &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sp_cmli_id &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data UTP_REDBULL_DF_3; set UTP_REDBULL_DF_2;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; by luid&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; dsp_display_cmli_id &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; display_cmli_id &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sp_cmli_id &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if first.luid then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_dsp_display_imps=0;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_display_imps=0;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_sp_clicks=0;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; retain &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_dsp_display_imps&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_display_imps&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_sp_clicks&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; *-- Counting total impressions and clicks by luid --*;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; dsp_display_prev=lag(dsp_display_cmli_id); if upcase(dsp_display_cmli_id) ^=upcase(dsp_display_prev) then dsp_total_display_imps+1;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; display_prev =lag(display_cmli_id); if display_cmli_id ^=display_prev then total_display_imps+1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; sp_prev =lag(sp_cmli_id); if sp_cmli_id ^=sp_prev then total_sp_clicks+1;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; keep&amp;nbsp; luid&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; dsp_display_cmli_id &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; display_cmli_id &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sp_cmli_id &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; dsp_display_prev&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; display_prev &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; sp_prev&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_display_imps &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_dsp_display_imps &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_sp_clicks &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; ;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc print data=UTP_REDBULL_DF_3;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; var luid&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; dsp_display_cmli_id &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; display_cmli_id &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; sp_cmli_id &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; dsp_display_prev&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; display_prev &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; &amp;nbsp; sp_prev&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_display_imps &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_dsp_display_imps &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; total_sp_clicks &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; ;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 19:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896524#M354243</guid>
      <dc:creator>Kaushansky</dc:creator>
      <dc:date>2023-09-29T19:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896526#M354244</link>
      <description>&lt;P&gt;Help us help you:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Please provide sample data in the form of a &lt;STRONG&gt;working DATA step, &lt;/STRONG&gt;not a csv file&lt;STRONG&gt;.&lt;/STRONG&gt;&amp;nbsp; This will&amp;nbsp; increase the number of respondents who will develop code to help resolve your problem.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Please show what you got from your program.&lt;/LI&gt;
&lt;LI&gt;Please show what you expected to get, and describe how it is different from what you got.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 21:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896526#M354244</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-29T21:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896528#M354245</link>
      <description>&lt;P&gt;Tell us exactly what you see that makes you think that the LAG function is not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example data only shows one value of LUID, so anything related to multiple values of that variable can't be seen.&lt;/P&gt;
&lt;P&gt;Since you say the output is wrong, then show, for that given example what should be correct.&lt;/P&gt;
&lt;P&gt;When I use this data set created using your CSV values (and this is how you should share data) I do not see anything that the LAG function is not working. I see suspect accumulators but the LAG looks correct.&lt;/P&gt;
&lt;PRE&gt;data UTP_REDBULL_DF_2;
   infile datalines dlm=',';
   input luid :$10. display_cmli_id :$10. dsp_display_cmli_id :$10. sp_cmli_id :$10.;
datalines;
1027774874,6261781089,3g6gzrq,1744739
1027774874,6261781089,3g6gzrq,1744739
1027774874,6261781089,3g6gzrq,1744739
1027774874,6261781089,3g6gzrq,1744739
1027774874,6261781089,3g6gzrq,1744739
1027774874,6261781089,56vcsen,1744739
1027774874,6261781089,56vcsen,1744739
1027774874,6261781089,56vcsen,1744739
1027774874,6261781089,56vcsen,1744739
1027774874,6261781089,56vcsen,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,b9rq6w4,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dkha69c,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,dryvhem,1744739
1027774874,6261781089,im7u5uh,1744739
1027774874,6261781089,im7u5uh,1744739
1027774874,6261781089,im7u5uh,1744739
1027774874,6261781089,im7u5uh,1744739
1027774874,6261781089,im7u5uh,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,q7c5l1c,1744739
1027774874,6261781089,v2libkt,1744739
1027774874,6261781089,v2libkt,1744739
1027774874,6261781089,v2libkt,1744739
1027774874,6261781089,v2libkt,1744739
1027774874,6261781089,v2libkt,1744739
;
&lt;/PRE&gt;
&lt;P&gt;Your example data also only has one value for dsp_display_cmli_id and one value for&amp;nbsp;sp_cmli_id so it is hard to see a likely problem with LAG associated with those variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may also help to describe a bit more about what this is supposed to do.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 21:53:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896528#M354245</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-29T21:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896539#M354251</link>
      <description>&lt;P&gt;The lag() function is working as designed.&lt;/P&gt;
&lt;P&gt;I believe what caused an unexpected result for you was due to the total_* variables already existing in source. Because these variables exist already in source the retain statement on these variables doesn't have the effect you thought it would.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does below code return what you're after?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data UTP_REDBULL_DF_3;
  set UTP_REDBULL_DF_2(rename=(
                          total_dsp_display_imps=_src_total_dsp_display_imps
                          total_display_imps    =_src_total_display_imps
                          total_sp_clicks       =_src_total_sp_clicks
                          ));
  by luid
    dsp_display_cmli_id  
    display_cmli_id  
    sp_cmli_id  
  ;

  if first.luid then
    do;
      total_dsp_display_imps=0;
      total_display_imps=0;
      total_sp_clicks=0;
    end;

  retain
    total_dsp_display_imps
    total_display_imps
    total_sp_clicks
  ;

  *-- Counting total impressions and clicks by luid --*;
  dsp_display_prev=lag(dsp_display_cmli_id);
  if first.luid or upcase(dsp_display_cmli_id) ^=upcase(dsp_display_prev) then
    total_dsp_display_imps+1;

  display_prev =lag(display_cmli_id);
  if first.luid or display_cmli_id ^=display_prev then
    total_display_imps+1;

  sp_prev =lag(sp_cmli_id);
  if first.luid or sp_cmli_id ^=sp_prev then
    total_sp_clicks+1;

  keep  luid
    dsp_display_cmli_id
    display_cmli_id
    sp_cmli_id

    dsp_display_prev
    display_prev
    sp_prev

    total_display_imps  
    total_dsp_display_imps  
    total_sp_clicks  
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also assume that you intended in below code section to call your variable &lt;STRONG&gt;total&lt;/STRONG&gt;_&lt;STRONG&gt;dsp&lt;/STRONG&gt;_display_imps and not dsp_total_...&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1696038051735.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88452i0D93F583E1EE151C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1696038051735.png" alt="Patrick_0-1696038051735.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Below a variant for above code that should return the same result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data UTP_REDBULL_DF_3;
  set UTP_REDBULL_DF_2(drop=total_:);
  by luid
    dsp_display_cmli_id  
    display_cmli_id  
    sp_cmli_id  
  ;

  if first.luid then
    do;
      total_dsp_display_imps=0;
      total_display_imps=0;
      total_sp_clicks=0;
    end;

  *-- Counting total impressions and clicks by luid --*;
  _check= upcase(dsp_display_cmli_id) ^=upcase(lag(dsp_display_cmli_id));
  if first.luid or _check  then
    total_dsp_display_imps+1;

  _check= display_cmli_id ^=lag(display_cmli_id);
  if first.luid or _check then
    total_display_imps+1;

  _check= sp_cmli_id ^=lag(sp_cmli_id);
  if first.luid or _check then
    total_sp_clicks+1;

  keep  luid
    dsp_display_cmli_id
    display_cmli_id
    sp_cmli_id

    dsp_display_prev
    display_prev
    sp_prev

    total_display_imps  
    total_dsp_display_imps  
    total_sp_clicks  
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2023 01:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896539#M354251</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-30T01:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896566#M354261</link>
      <description>&lt;P&gt;Thank you, the latest code worked (below). I still do not understand why my original code could not match the&amp;nbsp;dsp_display_cmli_id to the prev variable? Also what is&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;(drop=total_:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Meant to do? I took it out since it was giving me an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2023 15:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896566#M354261</guid>
      <dc:creator>Kaushansky</dc:creator>
      <dc:date>2023-09-30T15:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896569#M354263</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373742"&gt;@Kaushansky&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;Also what is&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;(drop=total_:);&lt;/LI-CODE&gt;
&lt;P&gt;Meant to do? I took it out since it was giving me an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Patrick had guessed that maybe your dataset&amp;nbsp;&lt;CODE class=" language-sas"&gt;UTP_REDBULL_DF_2&lt;/CODE&gt; already has variables named&amp;nbsp;total_dsp_display_imps etc.&amp;nbsp; Is that correct? If so, you don't want to read them in the DATA step, because they will collide with the variables you are creating in the step as accumulators.&amp;nbsp; Therefore drop= will not read in any variables that start with total_&amp;nbsp; . But if this was throwing an error when you ran it, that suggests these variables don't actually exist in UTP_REDBULL_DF_2. So Patrick's guess as to the cause of the problem may have been wrong, but sounds like the code Patrick wrote is right. : )&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 UTP_REDBULL_DF_3;
  set UTP_REDBULL_DF_2(drop=total_:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Sep 2023 15:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896569#M354263</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-30T15:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: LAG function not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896582#M354273</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373742"&gt;@Kaushansky&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've reject the .csv you've shared and it doesn't contain any variables names starting with total_* Looks like I've got "confused" when testing my code. Just remove this portion of the code as you've already done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I still do not understand why my original code could not match the&amp;nbsp;dsp_display_cmli_id to the prev variable?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's because there are TWO variables. The one you use for aggregation is called &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;dsp_total&lt;/FONT&gt;_display_imps&lt;/STRONG&gt;, the one you initialize with zero and use in your retain and keep list is called&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;total_dsp&lt;/FONT&gt;_display_imps&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2023 05:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-function-not-working/m-p/896582#M354273</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-01T05:01:07Z</dc:date>
    </item>
  </channel>
</rss>

