Hi all, This one is quite frustrating. I want to return the Nth word of a string which matches (NOT case-sensitive) my 'search term'. Illustrated with example code using sashelp dataset. My code : *Create string which will be searched;
%let allowedTeams=montreal Cleveland ATLANTA houston Pittsburgh;
*Test dataset;
data work.baseballTest (drop=allowedT);
set sashelp.baseball(keep=team );
if _n_ < 20;
allowedT='montreal Cleveland ATLANTA houston Pittsburgh';
*Various styles of findw None of which appear to work;
findwRes1 = findw("&allowedTeams",team,' ','ei');
findwRes2= findw(allowedT,team,' ','e i');
findwRes3= findw("montreal Cleveland ATLANTA houston Pittsburgh",team,' ','e i');
findwRes4= findw(upcase("&allowedTeams"),upcase(team),' ','E');
findwRes5= findw("&allowedTeams",team,' ','i');
findwRes6= findw("&allowedTeams",team);
*Indexw locates the string. But extra work is needed to get the ;
*number of the word in the string;
indexwRes= indexw(upcase("&allowedTeams"), upcase(team));
if indexwres > 0 then do;
indexwRes1= countw(substr("&allowedTeams", 1, indexwRes), ' ', 'i');
end;
run; On running this code I attempt several different ways to get the FINDW to work for me (findwRres1-6) . Looking in the resultant dataset none of them do as they are all =0. I am able to use a workaround using indexw and countw (as shown) which does work correctly but is not as slick as the FINDW solution would be. Can anyone suggest what is going wrong with my findw attempts?
... View more