<?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 Not Copying Data Lag Line in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LAG-Not-Copying-Data-Lag-Line/m-p/699227#M213888</link>
    <description>&lt;P&gt;I am running the following command:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= rt2 ; by day dayrank ; run ;
data rt2 ; set rt2 ; by day dayrank ;
	if users = lag(users) then dayrank = lag(dayrank) ; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It is yielding the following results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ericdrosano_1-1605545377723.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51726iE978FD387BD5B5D1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ericdrosano_1-1605545377723.png" alt="ericdrosano_1-1605545377723.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;#&lt;/TD&gt;&lt;TD&gt;security&lt;/TD&gt;&lt;TD&gt;day&lt;/TD&gt;&lt;TD&gt;users&lt;/TD&gt;&lt;TD&gt;dayrank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;WB&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6481&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;BIDU&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6349&lt;/TD&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;OKTA&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6349&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;MNKD&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6296&lt;/TD&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before running the code, the value in line 125 column 4 was 125. The 'dayrank' column is BEST12. Numeric. &lt;STRONG&gt;Why is it changing the 'dayrank' value in line 125 to '.' instead of 124 when OKTA's users are the same as BIDU's on 02MAY2018?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;P.S. - I have also run the code where I include "descending users" as part of the sorting, but it results in the same problem.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Nov 2020 16:59:32 GMT</pubDate>
    <dc:creator>ericdrosano</dc:creator>
    <dc:date>2020-11-16T16:59:32Z</dc:date>
    <item>
      <title>LAG Not Copying Data Lag Line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-Not-Copying-Data-Lag-Line/m-p/699227#M213888</link>
      <description>&lt;P&gt;I am running the following command:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= rt2 ; by day dayrank ; run ;
data rt2 ; set rt2 ; by day dayrank ;
	if users = lag(users) then dayrank = lag(dayrank) ; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It is yielding the following results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ericdrosano_1-1605545377723.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51726iE978FD387BD5B5D1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ericdrosano_1-1605545377723.png" alt="ericdrosano_1-1605545377723.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;#&lt;/TD&gt;&lt;TD&gt;security&lt;/TD&gt;&lt;TD&gt;day&lt;/TD&gt;&lt;TD&gt;users&lt;/TD&gt;&lt;TD&gt;dayrank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;WB&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6481&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;BIDU&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6349&lt;/TD&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;TD&gt;OKTA&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6349&lt;/TD&gt;&lt;TD&gt;125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;TD&gt;MNKD&lt;/TD&gt;&lt;TD&gt;02MAY2018&lt;/TD&gt;&lt;TD&gt;6296&lt;/TD&gt;&lt;TD&gt;126&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before running the code, the value in line 125 column 4 was 125. The 'dayrank' column is BEST12. Numeric. &lt;STRONG&gt;Why is it changing the 'dayrank' value in line 125 to '.' instead of 124 when OKTA's users are the same as BIDU's on 02MAY2018?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;P.S. - I have also run the code where I include "descending users" as part of the sorting, but it results in the same problem.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 16:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-Not-Copying-Data-Lag-Line/m-p/699227#M213888</guid>
      <dc:creator>ericdrosano</dc:creator>
      <dc:date>2020-11-16T16:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: LAG Not Copying Data Lag Line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-Not-Copying-Data-Lag-Line/m-p/699230#M213890</link>
      <description>&lt;P&gt;Never use LAG conditionally. It only puts values into its FIFO queue when it is called, so a conditional call to the function will skip values.&lt;/P&gt;
&lt;P&gt;You can use the IFN function to avoid this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=rt2;
by day dayrank;
run;

data rt2;
set rt2;
by day dayrank;
dayrank = ifn(users = lag(users),lag(dayrank),dayrank);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The IFN (and IFC) function executes all arguments before deciding which to use.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 17:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-Not-Copying-Data-Lag-Line/m-p/699230#M213890</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-16T17:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: LAG Not Copying Data Lag Line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LAG-Not-Copying-Data-Lag-Line/m-p/699246#M213901</link>
      <description>&lt;P&gt;Your solution was the correct solution for the question I asked; thank you!&lt;/P&gt;&lt;P&gt;What is funny is that I discovered that all I had ever needed to do was to use the proc rank statement initially, and then I would have never had the problem I created for myself in the first place!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":upside_down_face:"&gt;🙃&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data= rt2 out= test ties= low descending ; by day ; var users ; ranks usersrank; run ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Nevertheless, thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 18:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LAG-Not-Copying-Data-Lag-Line/m-p/699246#M213901</guid>
      <dc:creator>ericdrosano</dc:creator>
      <dc:date>2020-11-16T18:04:13Z</dc:date>
    </item>
  </channel>
</rss>

