I have a list of counties in a dataset (Calhoun County, El Paso County, etc.) and would like to return a dataset that has the word 'County' stripped (Calhoun, El Paso, etc.) Is there an easy way to do this in SAS? Thank you!
1
votes
1 Answers
2
votes
CALL SCAN will report the position of the nth word, which then you can use with substr. Count=-1 will look from the end rather than the beginning.
data _null_;
starting_word='El Paso County';
count=-1;
call scan(starting_word, count, pos, length);
end_word=substr(starting_word,1,pos-2); *pos will be the 'C' so back two;
put end_word=;
run;