There you go! The key is applying strip() to remove blanks (mainly trailing blanks here):
data gafi_countries;
input gafi $20.;
cards;
bolivie
chypre
cyprus
équateur
equateur
éthiopie
ethiopie
indo
kenya
nigeria
nigéria
pakistan
sao
lanka
tanzanie
thai
tailand
turquie
viet
yemen
yémen
;
data sanction_countries;
input sanction $20.;
cards;
bélarus
belarus
chine
congo
rpdc
rdc
coree
corée
ivoire
cuba
érythrée
erythree
iran
iraq
irak
liban
lebanon
liberia
libéria
libye
lybie
lybia
myanmar
birmanie
sierra
somalie
somalia
soudan
sudan
syrie
zimbabwe
;
data mytest;
input objet $20.;
cards;
belarus acc
belarus refus
somalia acc
somalia refus
bolivie acc
bolivie refus
chypre acc
chypre refus
john
bob
;
data want;
if _n_=1 then do;
if 0 then set gafi_countries sanction_countries;
declare hash g(dataset:'gafi_countries');
g.definekey('gafi');
g.definedone();
declare hiter hig('g');
declare hash s(dataset:'sanction_countries');
s.definekey('sanction');
s.definedone();
declare hiter his('s');
end;
set mytest end=last;
_temp=sum(count_gafi_acc,count_gafi_refus, count_sanction_acc, count_sanction_refus);
do rc=hig.first() by 0 while (rc=0);
if find(objet, strip(gafi), 'i') and find(objet, 'acc','i') then count_gafi_acc+1;
if find(objet, strip(gafi), 'i') and find(objet, 'refus','i') then count_gafi_refus+1;
rc=hig.next();
end;
do rc=his.first() by 0 while (rc=0);
if find(objet, strip(sanction), 'i') and find(objet, 'acc','i') then count_sanction_acc+1;
if find(objet, strip(sanction), 'i') and find(objet, 'refus','i') then count_sanction_refus+1;
rc=his.next();
end;
if _temp >= sum(count_gafi_acc,count_gafi_refus, count_sanction_acc, count_sanction_refus) then count_person+1;
if last then output;
keep count_gafi_acc count_gafi_refus count_sanction_acc count_sanction_refus count_person;
run;
Haikuo
This works perfectly!
Thank you very much for your help and time.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: