<?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: Deleting Observations based on a pattern in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553780#M16978</link>
    <description>It is very close! This gets me all those who had an occurrence and then had missing data. I do want to keep these individuals in addition to the other 1494 with complete data.&lt;BR /&gt;&lt;BR /&gt;Like always, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, great use of the compress(cats()). That's very handy and a clever way to deal with this.</description>
    <pubDate>Wed, 24 Apr 2019 19:55:16 GMT</pubDate>
    <dc:creator>joebacon</dc:creator>
    <dc:date>2019-04-24T19:55:16Z</dc:date>
    <item>
      <title>Deleting Observations based on a pattern</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553753#M16976</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It has been a little while. I come back to you with what I think should be a pretty simple request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which i trimmed down to 5 variables. It looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.NEO;
  infile datalines dsd truncover;
  input PUBID:BEST. R1HDRK_Dummy:BEST. R2HDRK_Dummy:BEST. R3HDRK_Dummy:BEST. R4HDRK_Dummy:BEST. R5HDRK_Dummy:BEST.;
  format PUBID BEST. R1HDRK_Dummy BEST. R2HDRK_Dummy BEST. R3HDRK_Dummy BEST. R4HDRK_Dummy BEST. R5HDRK_Dummy BEST.;
  label PUBID="PUBID" R1HDRK_Dummy="R1HDRK_Dummy" R2HDRK_Dummy="R2HDRK_Dummy" R3HDRK_Dummy="R3HDRK_Dummy" R4HDRK_Dummy="R4HDRK_Dummy" R5HDRK_Dummy="R5HDRK_Dummy";
datalines;
2 0 0 3 0 0
7 0 0 0 0 5
10 0 0 0 0 0
21 1 0 0 0 0
22 1 0 0 0 0
23 0 0 . . 5
29 0 0 0 0 .
31 0 0 0 0 0
35 0 0 3 0 .
41 0 0 0 0 0
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to work on a survival model. As such, I ran a missing data report to find that out of the 1858 observations, 1494 have complete data. However, I would like to include some of the incomplete data as these variables are simple, dichotomous dummy-coded variables. Each variable is a different year (1-5). I would ideally like to keep any data that has an occurrence and then is missing. For instance, I would like to keep line 9 (PID 35) because they reported binge drinking in their 3rd year, but then had missing data. Eventually, I will replace the missing values after the first occurrence with 0's but right now I am focused on the deletion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not want any occurrence that I cannot tell if it was their first year binge drinking. For example, line 6 (PID 23) reported a case of binge drinking in year 5, but I do not know if they also did in year 3 or 4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to see if anyone had any opinion on if this is best practice with deleting missing values for a survival model as well as some suggestions on code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using the following code, but the number remaining, 1576 seems rather low. I also know that this code is not streamlined, but it was the best I could do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Neo_Clean;
set neo;
if missing(R1HDRK_Dummy) and missing(R2HDRK_Dummy) and missing(R3HDRK_Dummy) and missing(R4HDRK_Dummy) and missing(R5HDRK_Dummy)  then delete;
if missing(R1HDRK_Dummy) then delete;
if  R5HDRK_Dummy &amp;gt; 0 and missing(R1HDRK_Dummy) or missing(R2HDRK_Dummy) or missing(R3HDRK_Dummy) or missing(R4HDRK_Dummy) then delete;
if  R4HDRK_Dummy &amp;gt; 0 and missing(R1HDRK_Dummy) or missing(R2HDRK_Dummy) or missing(R3HDRK_Dummy) then delete;
if  R3HDRK_Dummy &amp;gt; 0 and missing(R1HDRK_Dummy) or missing(R2HDRK_Dummy) then delete;
if  R2HDRK_Dummy &amp;gt; 0 and missing(R1HDRK_Dummy)  then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 19:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553753#M16976</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2019-04-24T19:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Observations based on a pattern</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553774#M16977</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure whether my understanding is accurate. But is this what you are after by any chance?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.NEO;
  infile datalines  truncover;
  input PUBID:BEST. R1HDRK_Dummy:BEST. R2HDRK_Dummy:BEST. R3HDRK_Dummy:BEST. R4HDRK_Dummy:BEST. R5HDRK_Dummy:BEST.;
  format PUBID BEST. R1HDRK_Dummy BEST. R2HDRK_Dummy BEST. R3HDRK_Dummy BEST. R4HDRK_Dummy BEST. R5HDRK_Dummy BEST.;
  label PUBID="PUBID" R1HDRK_Dummy="R1HDRK_Dummy" R2HDRK_Dummy="R2HDRK_Dummy" R3HDRK_Dummy="R3HDRK_Dummy" R4HDRK_Dummy="R4HDRK_Dummy" R5HDRK_Dummy="R5HDRK_Dummy";
datalines;
2 0 0 3 0 0
7 0 0 0 0 5
10 0 0 0 0 0
21 1 0 0 0 0
22 1 0 0 0 0
23 0 0 . . 5
29 0 0 0 0 .
31 0 0 0 0 0
35 0 0 3 0 .
41 0 0 0 0 0
;;;;

data want;
set neo;
k=compress(cats(of R1HDRK_Dummy--R5HDRK_Dummy),'0');
if anydigit(k)=1 and index(k,'.') ;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Apr 2019 19:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553774#M16977</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-24T19:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Observations based on a pattern</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553780#M16978</link>
      <description>It is very close! This gets me all those who had an occurrence and then had missing data. I do want to keep these individuals in addition to the other 1494 with complete data.&lt;BR /&gt;&lt;BR /&gt;Like always, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, great use of the compress(cats()). That's very handy and a clever way to deal with this.</description>
      <pubDate>Wed, 24 Apr 2019 19:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553780#M16978</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2019-04-24T19:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Observations based on a pattern</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553781#M16979</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;&amp;nbsp;I do want to keep these individuals&lt;STRONG&gt; in addition to the other 1494 with complete data."&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am not understanding. Do you mean you just want to Flag?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 19:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553781#M16979</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-24T19:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Observations based on a pattern</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553783#M16980</link>
      <description>I can work with what you gave.&lt;BR /&gt;&lt;BR /&gt;It outputs the 77 individuals who had an occurrence and then went missing. I also want to include in that dataset the 1494 that have no missing data. I will just merge the two datasets &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 24 Apr 2019 20:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553783#M16980</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2019-04-24T20:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Observations based on a pattern</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553784#M16981</link>
      <description>&lt;P&gt;Ok cool&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2019 20:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-Observations-based-on-a-pattern/m-p/553784#M16981</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-24T20:09:33Z</dc:date>
    </item>
  </channel>
</rss>

