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.   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   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.  Thank you 
						
					
					... View more