You can do it in one DATA step by using a hash object:
data lead_assistant_project;
infile datalines truncover dsd dlm='|';
input Lead_Writer:$8. Assistant_Writer:$40. Project:$40.;
datalines;
Joe|Mac,Maggie|Earwax for Dummies
Joe||Clock Repair
Sam|Joe|Desk Fans: A Celebration
;
data _null_;
set lead_assistant_project end=done;
if _n_ = 1
then do;
length
writer $8
total lead assistant 8
;
declare hash w (ordered:"yes");
w.definekey("writer");
w.definedata("writer","total","lead","assistant");
w.definedone();
end;
writer = lead_writer;
if w.find() = 0
then do;
total + 1;
lead + 1;
rc = w.replace();
end;
else do;
total = 1;
lead = 1;
assistant = 0;
rc = w.add();
end;
if assistant_writer ne "" then do i = 1 to countw(assistant_writer,",");
writer = scan(assistant_writer,i,",");
if w.find() = 0
then do;
total + 1;
assistant + 1;
rc = w.replace();
end;
else do;
total = 1;
lead = 0;
assistant = 1;
rc = w.add();
end;
end;
if done then rc = w.output(dataset:"want");
run;
... View more