<?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: how to remove the data which satisfy some critical conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369516#M88232</link>
    <description>&lt;P&gt;Ksharp,&lt;/P&gt;&lt;P&gt;It works! Thank you very much!&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 14:32:13 GMT</pubDate>
    <dc:creator>daisy6</dc:creator>
    <dc:date>2017-06-22T14:32:13Z</dc:date>
    <item>
      <title>how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369490#M88218</link>
      <description>&lt;P&gt;Hi SAS experts,&lt;/P&gt;&lt;P&gt;I have a data in which there are many students and severals exams. If one&amp;nbsp;student does not anwer all the questions, how do I eliminate him? For example:&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input id$ answerkey$ response$ responsestatus$;&lt;BR /&gt;cards;&lt;BR /&gt;1 A B answered&lt;BR /&gt;1 C C answered&lt;BR /&gt;1 D D answered&lt;BR /&gt;1 B B answered&lt;BR /&gt;2 A B answered&lt;BR /&gt;2 C unanswered&lt;BR /&gt;2 D D answered&lt;BR /&gt;2 B B answered&lt;BR /&gt;3 A c answered&lt;BR /&gt;3 C C answered&lt;BR /&gt;3 D unanswered&lt;BR /&gt;3 B B answered&lt;BR /&gt;4 A C answered&lt;BR /&gt;4 C C answered&lt;BR /&gt;4 D C answered&lt;BR /&gt;4 B B answered&lt;BR /&gt;5 A unanswered&lt;BR /&gt;5 C unanswered&lt;BR /&gt;5 D unanswered&lt;BR /&gt;5 B unanswered&lt;BR /&gt;6 A B answered&lt;BR /&gt;6 C C answered&lt;BR /&gt;6 D c answered&lt;BR /&gt;6 B B answered&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to get rid of id=5?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369490#M88218</guid>
      <dc:creator>daisy6</dc:creator>
      <dc:date>2017-06-22T14:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369498#M88222</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  delete from A where RESPONSE_STATUS="unanswered";
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369498#M88222</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-22T14:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369507#M88225</link>
      <description>&lt;P&gt;This depends somewhat on how your data are formatted. &amp;nbsp;If the "answered/unanswered" variables are stored as 0/1, it could be just as &amp;nbsp;easy as summing the responses and using a WHERE condition:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;TotalResp = A + B + C + D + E

... 

WHERE TotalResp = 5&lt;/PRE&gt;&lt;P&gt;Otherwise, you could compute the number of responses missing&amp;nbsp;this way using the missing function. Then, exclude those for which all are blank:&lt;/P&gt;&lt;PRE&gt;Total_Blank_Resp = missing( A ) + missing( B ) + missing( C ) + missing( D ) + missing( E )

...

WHERE Total_Blank_Resp = 5&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369507#M88225</guid>
      <dc:creator>Cochetti</dc:creator>
      <dc:date>2017-06-22T14:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369509#M88227</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input id$ answerkey$ response$ responsestatus : $20.;
cards;
1 A B answered
1 C C answered
1 D D answered
1 B B answered
2 A B answered
2 C . unanswered
2 D D answered
2 B B answered
3 A c answered
3 C C answered
3 D . unanswered
3 B B answered
4 A C answered
4 C C answered
4 D C answered
4 B B answered
5 A . unanswered
5 C . unanswered
5 D . unanswered
5 B . unanswered
6 A B answered
6 C C answered
6 D c answered
6 B B answered
;
run;
proc sql;
select *
 from a 
  group by id 
   having sum(responsestatus='unanswered') ne count(*);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369509#M88227</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-22T14:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369510#M88228</link>
      <description>&lt;P&gt;As I understand, if I use the code you provided, it will eliminate &amp;nbsp;id=3 question3 since it is unanswered?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369510#M88228</guid>
      <dc:creator>daisy6</dc:creator>
      <dc:date>2017-06-22T14:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369511#M88229</link>
      <description>&lt;P&gt;First off, the data set as written won't work as intended. The missing values for 'response' cause the variables to be read in wrong. There are many ways to fix this. I just manually added spaces to align the variables and updated the input statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input id$ answerkey$ response$ 5 responsestatus$ 7-16;
cards;
1 A B answered
1 C C answered
1 D D answered
1 B B answered
2 A B answered
2 C   unanswered
2 D D answered
2 B B answered
3 A C answered
3 C C answered
3 D   unanswered
3 B B answered
4 A C answered
4 C C answered
4 D C answered
4 B B answered
5 A   unanswered
5 C   unanswered
5 D   unanswered
5 B   unanswered
6 A B answered
6 C C answered
6 D c answered
6 B B answered
;
run;

*Creates a running total for the number of answers per ID then only outputs those with 4 answered questions and not ID of 5;
data b (drop=answer_flag answer_count);
set a;
by id;
if first.id then answer_count=0;

answer_flag=(responsestatus="answered"); 
answer_count+answer_flag;

if last.id then do;
  if answer_count = 4 and id ^= "5" then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369511#M88229</guid>
      <dc:creator>Rwon</dc:creator>
      <dc:date>2017-06-22T14:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369512#M88230</link>
      <description>&lt;P&gt;Ah, just reverse the logic then:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table TMP as select * from A where RESPONSE_STATUS="answered";
  delete from A where ID not in (select ID from TMP);
quit;&lt;/PRE&gt;
&lt;P&gt;Ie if there is not an answered for that ID delete it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369512#M88230</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-22T14:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369516#M88232</link>
      <description>&lt;P&gt;Ksharp,&lt;/P&gt;&lt;P&gt;It works! Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369516#M88232</guid>
      <dc:creator>daisy6</dc:creator>
      <dc:date>2017-06-22T14:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to remove the data which satisfy some critical conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369518#M88234</link>
      <description>Thank all of you for the help!</description>
      <pubDate>Thu, 22 Jun 2017 14:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-remove-the-data-which-satisfy-some-critical-conditions/m-p/369518#M88234</guid>
      <dc:creator>daisy6</dc:creator>
      <dc:date>2017-06-22T14:36:29Z</dc:date>
    </item>
  </channel>
</rss>

