<?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 Keeping observations by longidutinal data techniques in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421418#M103667</link>
    <description>&lt;P&gt;I have a longitudinal dataset (assuming it is already sorted by increasing time):&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp;&amp;nbsp; DX&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to keep the observations in the dataset where DX is 1 or 2. But, if DX is 0, I only want to throw it out if (1) it is the only record for that ID or (2) if it is the first observation for that ID and is followed by a DX of 1 or 2.For the example above, it would look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp;&amp;nbsp; DX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I do this? Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 15 Dec 2017 00:27:17 GMT</pubDate>
    <dc:creator>Melk</dc:creator>
    <dc:date>2017-12-15T00:27:17Z</dc:date>
    <item>
      <title>Keeping observations by longidutinal data techniques</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421418#M103667</link>
      <description>&lt;P&gt;I have a longitudinal dataset (assuming it is already sorted by increasing time):&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp;&amp;nbsp; DX&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to keep the observations in the dataset where DX is 1 or 2. But, if DX is 0, I only want to throw it out if (1) it is the only record for that ID or (2) if it is the first observation for that ID and is followed by a DX of 1 or 2.For the example above, it would look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ID&amp;nbsp;&amp;nbsp; DX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I do this? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 00:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421418#M103667</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-12-15T00:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations by longidutinal data techniques</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421420#M103668</link>
      <description>&lt;P&gt;Assuming that an ID can't have two instances of DX=0, you could try:&lt;/P&gt;
&lt;P&gt;data work.want;&lt;BR /&gt;&amp;nbsp; set work.have;&lt;BR /&gt;&amp;nbsp; by ID;&lt;BR /&gt;&amp;nbsp; if DX eq 0 then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if (first.ID and last.ID) then delete;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else if (first.ID and not last.ID) then delete;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 00:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421420#M103668</guid>
      <dc:creator>DaveBirch</dc:creator>
      <dc:date>2017-12-15T00:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations by longidutinal data techniques</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421421#M103669</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be straightforward:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID   DX  @@;
datalines;
1 0   2 1   2 0   3 2
4 0   4 1   4 2   5 0
run;

data want ;
  set have (keep=id);
  by id ;
  merge have have (firstobs=2 keep=dx rename=(dx=nxt_dx));
  if first.id=1 and dx=0 and (last.id=1 or nxt_dx in (1,2)) then delete;
run;&lt;/CODE&gt;&lt;/PRE&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;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The if test asks whether&amp;nbsp;the id starts with 0, ("first.id=1 and dx=0"),&amp;nbsp;&amp;nbsp; and whether that zero is a single record ("and last.id=1") or is followed by a 1 or 2 ("nxt_dx in (1,2)").&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 01:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421421#M103669</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-15T01:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations by longidutinal data techniques</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421425#M103670</link>
      <description>&lt;P&gt;Hi, Your sample makes me wonder whether a "Look Ahead" is even required once you determine the value of first.id is 0? Perhaps my bad, i should assume the look ahead obs could have any other number besides 0,1,2.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2017 02:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421425#M103670</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-12-15T02:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping observations by longidutinal data techniques</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421438#M103677</link>
      <description>I think you are right, I only care about observations that start with my diagnosis of interest, I suppose in the case of a 0 then a 0 then a 1, I would then throw out the first 2 observations though.</description>
      <pubDate>Fri, 15 Dec 2017 06:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-observations-by-longidutinal-data-techniques/m-p/421438#M103677</guid>
      <dc:creator>Melk</dc:creator>
      <dc:date>2017-12-15T06:15:51Z</dc:date>
    </item>
  </channel>
</rss>

