SAS Version 9.4
Good day and thank you for looking at my question.
data work.have;
infile datalines dlm=' ';
input CN $1. @5 SEN $1. @9 RT $1. @12 Value;
datalines;
x p d 5
x p b 7
x u d 6
x u b 8
y t d 2
y t b 8
z t d 3
z t b 9
q p d 4
q p b 6
;
run;
proc sort data=work.have; by cn sen; run;
The sorted dataset, work.have, is identical to the original.
For each unique CN, I need to check that the first observation of SEN is the same as the second observation of SEN.
Also, I need the first RT to be D or B; if D then the second RT should be B; if B, then the second RT should be D.
Finally, I need to calculate the sum of the 2 VALUES that meet these conditions.
The resulting dataset should look like this:
![4.JPG 4.JPG](https://communities.sas.com/t5/image/serverpage/image-id/30927iB034F3F4B5A94FA4/image-size/large?v=v2&px=999)
My attempts have failed, but I have this:
data work.want;
set work.have;
by CN SEN;
sumit=0;
if first.CN and first.sen then do;
count=0;
save_value1=value;
end;
count+1;
sumit=save_value1;
if last.cn and last.sen then save_value2=value;
sumit+save_value2;
run;
proc print data=work.want; run;
Thank you for assistance.
Jane