You could just keep trying to match shorter and shorter versions of STRING_1 to the beginning of STRING_2 until you find a match. You can add a little wrinkle to make sure a space gets added when there is no match.
data have;
infile datalines dsd truncover ;
input String_1 :$100. String_2 :$100. Want :$150.;
datalines;
MOTOR LATCH 854A LATCH DRYER FOR EC,LATCH DRYER FOR ECCENTRIC MOTOR OUT,MOTOR LATCH 854A LATCH DRYER FOR ECCENTRIC MOTOR OUT
ROTOR DC LEM9984T 3 5 HP 1560 RPM 29,3 5 HP 1560 RPM 295TC DRAIN,ROTOR DC LEM9984T 3 5 HP 1560 RPM 295TC DRAIN
aaa,,aaa
,bbb,bbb
aaa,bbb,aaa bbb
;
data want;
set have;
length combo $150;
do lp=1 to lengthn(string_1) until(substrn(string_1,lp,lengthn(string_1)-lp+1)=:string_2); end;
if lp > length(string_1) then lp+1;
combo=substrn(string_1||' ',1,lp-1) || string_2;
match=combo=want;
run;
proc print;
run;
Results:
... View more