<?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: selecting unique cases in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/selecting-unique-cases/m-p/403361#M12249</link>
    <description>&lt;P&gt;Brilliant! Yes, I always start with two observations for each YEARCASE. I tried this and it worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your solution.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2017 20:47:47 GMT</pubDate>
    <dc:creator>stunt</dc:creator>
    <dc:date>2017-10-11T20:47:47Z</dc:date>
    <item>
      <title>selecting unique cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/selecting-unique-cases/m-p/403315#M12244</link>
      <description>&lt;P&gt;I need help with my SAS code. I have a dataset (test) that have variables yearcase and case. Yearcase is a variable that indicates a 2-motor vehicle crash .Case is a binary variable that indicates each of the 2 cars involved in the crash. I want to create a dataset (test2) that only includes case=1( car that caused the crash) and case=0 (car that did not cause the crash). I want each yearcase (crash pair) to have the car that caused the crash and one that did not cause the crash. I want to exclude yearcases (2-motor vehicle crashes) in which both cars did not cause the crash (case=0) or in which both cars caused the crash (case=1). My code here yields the following output below. As you can see, I still have yearcases (crashes) in which either both cases caused the crash (case=1) or both cases did not cause the crash (case=0). I attempted to use flag variables nocase and bothcase but its not working.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data test2; 
set test;
retain nocase bothcase;
by yearcase;
if first.yearcase then case=nocase;
if last.yearcase then case=bothcase;
if bothcase=nocase then output;
run;

proc freq data=test2;
tables yearcase*case/norow nocol nopercent;
run;

Output looks like this:

                        case 
 yearcase        case= 0    case= 1       Total
 201410001        0           2          2
 201410007        0           2          2
 201410015        2           0          2
 201410024        1           1          2
 201410031        1           1          2
 201410036        0           2          2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I make sure I only have yearcases (2-motor vehicle crashes) in which there is only 1 car that caused the crash (case=1) and another that did not (case=0)? I may need to use flag variables..but i'm unsure how to. Any help is greatly appreciated.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 18:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/selecting-unique-cases/m-p/403315#M12244</guid>
      <dc:creator>stunt</dc:creator>
      <dc:date>2017-10-11T18:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: selecting unique cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/selecting-unique-cases/m-p/403355#M12248</link>
      <description>&lt;P&gt;Here's an approach.&amp;nbsp; Assuming you always start with two observations for each YEARCASE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by yearcase case;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by yearcase case;&lt;/P&gt;
&lt;P&gt;if (case=0 and first.yearcase and last.case)&lt;/P&gt;
&lt;P&gt;or (case=1 and last.yearcase and first.case);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 20:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/selecting-unique-cases/m-p/403355#M12248</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-11T20:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: selecting unique cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/selecting-unique-cases/m-p/403361#M12249</link>
      <description>&lt;P&gt;Brilliant! Yes, I always start with two observations for each YEARCASE. I tried this and it worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 20:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/selecting-unique-cases/m-p/403361#M12249</guid>
      <dc:creator>stunt</dc:creator>
      <dc:date>2017-10-11T20:47:47Z</dc:date>
    </item>
  </channel>
</rss>

