Hi @tsureshinvites 
 
You can try the below code. You can achieve exactly the same using a proc freq and then DATA/MERGE
/* Subject are failed in only one test of IE tests category */
proc sql noprint;
	create table want1 as
	select b.subject_id, b.Test_code, b.Result
	from (select *
		  from (select subject_id, result, count(result) as count
		  		from IE_Raw
		  		where result = 'Fail' and substr(Test_code,1,2) ='IE'  
		  		group by Subject_id, result)
		  where count = 1) as a left join
		  IE_Raw as b
	on a.subject_id = b.subject_id and a.result = b.result
	where substr(Test_code,1,2) ='IE';
quit;
/* Subject_id passed / failed only one test in EX tests category */
proc sql noprint;
	create table want2 as
	select b.subject_id, b.Test_code, b.Result
	from (select *
	 	  from (select subject_id, result, count(result) as count
		  		from IE_Raw
		  		where substr(Test_code,1,2) ='EX'
		  		group by Subject_id, result)
	   	  where count = 1) as a left join
	   	  		  IE_Raw as b
	on a.subject_id = b.subject_id and a.result = b.result
	where substr(Test_code,1,2) ='EX';
quit;
/* Final merge */
data want;
	set want1 want2;
run;