Hi, I have a table that contains a variable objet. I want to count the number of records that match certains parameters. Basically I have 5 groups with the following parameters : count_gafi_acc : objet needs to contain a specific string (those strings are listed below) and the string 'acc' to be counted count_gafi_ref : objet needs to contain a specific string and the string refus to be counted count_sanction_acc : objet needs to contain a specific string and the string 'acc' to be counted count_saction_refus : objet needs to contain a specific string and the string refus to be counted count_person : all the records that weren't part of the 4 previous group need to be counted here (in order to achieve that I used switch = "n" and switch = "y" in my code below. I'm sure this isn't the most efficient way to do it.) Now instead of hard coding the specific string for each group in the code, I would like to create a table named myparameters with two columns. One column called gafi, that contains the specific strings related to the two specific gafi groups and one called sanction related to the two sanction groups. I would then want to write a sas macro that would count each objet records against each specific parameters in myparameters table and provide the count for each of the 5 groups. Could you please help me write that macro code? I have written (with the help of some user of this forum) the following working code. Hope you understand what I am trying to achieve. Thank you for your help and time. data mcount; set mytable; by objet; switch = "n"; if _n_ eq 1 then do; count_gafi_acc=0; count_sanction_acc=0; count_gafi_refus=0; count_sanction_refus=0; count_person=0; end; if index(lowcase(strip(objet)),'bolivie')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'chypre')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'cyprus')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'équateur')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'equateur')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'éthiopie')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'ethiopie')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'indo')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'kenya')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'nigeria')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'nigéria')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'pakistan')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'sao')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'sri lanka')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'tanzanie')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'thai')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'tailand')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'turquie')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'viet')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'yemen')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'yémen')>0 and index(lowcase(strip(objet)),'acc')>0 then do; count_gafi_acc=count_gafi_acc+1; switch = "y"; end; if index(lowcase(strip(objet)),'bolivie')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'chypre')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'cyprus')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'équateur')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'equateur')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'éthiopie')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'ethiopie')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'indo')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'kenya')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'nigeria')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'nigéria')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'pakistan')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'sao')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'sri lanka')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'tanzanie')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'thai')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'tailand')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'turquie')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'viet')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'yemen')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'yémen')>0 and index(lowcase(strip(objet)),'refus')>0 then do; count_gafi_refus=count_gafi_refus+1; switch = "y"; end; if index(lowcase(strip(objet)),'bélarus')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'belarus' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'chine' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'congo' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'rpdc' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'rdc' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'coree')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'corée')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'ivoire' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'cuba' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'érythrée' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'erythree')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'iran' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'iraq' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'irak' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'liban' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'lebanon' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'liberia' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'libéria' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'libye' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'lybie' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'lybia' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'myanmar' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'birmanie')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'sierra' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'somalie' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'somalia' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'soudan')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'sudan')>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)), 'syrie' )>0 and index(lowcase(strip(objet)),'acc')>0 or index(lowcase(strip(objet)),'zimbabwe')>0 and index(lowcase(strip(objet)),'acc')>0 then do; count_sanction_acc=count_sanction_acc+1; switch = "y"; end; if index(lowcase(strip(objet)),'bélarus')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'belarus' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'chine' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'congo' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'rpdc' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'rdc' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'coree')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'corée')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'ivoire' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'cuba' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'érythrée' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'erythree')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'iran' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'iraq' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'irak' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'liban' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'lebanon' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'liberia' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'libéria' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'libye' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'lybie' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'lybia' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'myanmar' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'birmanie')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'sierra' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'somalie' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'somalia' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'soudan')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'sudan')>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)), 'syrie' )>0 and index(lowcase(strip(objet)),'refus')>0 or index(lowcase(strip(objet)),'zimbabwe')>0 and index(lowcase(strip(objet)),'refus')>0 then do; count_sanction_refus=count_sanction_refus+1; switch = "y"; end; if switch ="n" then do; count_person = count_person + 1; /* If the record is not part of count_gafi_acc, count_gafi_refus, count_sanction_acc or count_sanction_refus , I want it to be part of count_person */ end; if eof; run;
... View more