<?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: Lagging a date.. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617441#M19076</link>
    <description>&lt;P&gt;It must not have gone through because I did mark as solved.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jan 2020 14:08:59 GMT</pubDate>
    <dc:creator>accintron</dc:creator>
    <dc:date>2020-01-15T14:08:59Z</dc:date>
    <item>
      <title>Lagging a date..</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617301#M19052</link>
      <description>&lt;P&gt;&lt;STRONG&gt;So my code is&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data readms2;&lt;BR /&gt;set readms;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PRV_DC_DT = lag(DC_DT);&lt;BR /&gt;if _N_=1 then PRV_DC_DT = DC_DT;&lt;BR /&gt;format PRV_DC_DT date9.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PRV_DC_REASON = lag(PRIM_DSCH_REASON);&lt;BR /&gt;if _N_=1 then PRV_DC_REASON = PRIM_DSCH_REASON;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a unique client ID...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NUM_ADM =0 is the first admission NUM_ADM=1 is a readmission. Essentially when NUM_ADM=0, PRV_DC_DT and PRV_DC_REASON should be missing because they are the first admission so there is not another relevant record to lag from... I'm instead incorrectly getting lagged values from other client IDs when NUM_ADM=0...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;What am I missing here... what do&lt;/STRONG&gt;&lt;/EM&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;I need to make to my code to have the lagged values start on the NUM_ADM=1 record? Thanks in advance.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resulting, &lt;U&gt;incorrect&lt;/U&gt; table is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35327iB182A8EEC0832640/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&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;</description>
      <pubDate>Tue, 14 Jan 2020 20:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617301#M19052</guid>
      <dc:creator>accintron</dc:creator>
      <dc:date>2020-01-14T20:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Lagging a date..</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617311#M19055</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data readms2;
set readms;
PRV_DC_DT = lag(DC_DT);
if num_Adm=0 then PRV_DC_DT = .;
format PRV_DC_DT date9.;
PRV_DC_REASON = lag(PRIM_DSCH_REASON);
if num_Adm=0 then PRV_DC_REASON = ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 20:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617311#M19055</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-14T20:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Lagging a date..</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617321#M19056</link>
      <description>&lt;P&gt;Thank you Paige. I did add a by statement as well for my unique ID so combined with your suggested addition to my code it seems to have worked. I appreciate the help!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 21:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617321#M19056</guid>
      <dc:creator>accintron</dc:creator>
      <dc:date>2020-01-14T21:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Lagging a date..</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617324#M19057</link>
      <description>&lt;P&gt;Then bring this topic to a closure and mark Paige's response (or your own explanation) as the solution. It's good to be able to look at a list of topics and know which ones have not yet been marked solved.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 01:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617324#M19057</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-15T01:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Lagging a date..</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617441#M19076</link>
      <description>&lt;P&gt;It must not have gone through because I did mark as solved.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 14:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Lagging-a-date/m-p/617441#M19076</guid>
      <dc:creator>accintron</dc:creator>
      <dc:date>2020-01-15T14:08:59Z</dc:date>
    </item>
  </channel>
</rss>

