Is this what you need? WantString = substr(HaveString,1,indexw(string,'vs')-1); Edited to include data step code to show how my statement works: data Have;
length HaveString $100.;
HaveString='Black or African American vs White'; output;
HaveString='Hispanic or Latino vs White';output;
HaveString='Other Race vs White';output;
;
run;
data Want;
set Have;
WantString = substr(HaveString,1,indexw(HaveString,'vs')-1);
run; Editing again as I noticed that words such as 'Race' appear to be in the same column as the value for Race. In this case, this code will work: data Have;
length HaveString $100.;
HaveString='Race Black or African American vs White'; output;
HaveString='Race Hispanic or Latino vs White';output;
HaveString='Race Other Race vs White';output;
;
run;
data Want;
set Have;
WantString = substr(HaveString, indexw(HaveString,scan(HaveString,2)), indexw(HaveString,'vs')-length(substr(HaveString,1,indexw(HaveString,scan(HaveString,2)))));
run;
... View more