Hi all,
I generate a code below with a couple of arrays, is there any way to shorten the code ?
data filter_each_country;
set concatenate_;
array delwords1 {18} $ 15 _temporary_ ('PN' 'PNA' 'PNB' 'PNC' 'PND' 'PNE' 'PNF'
'PNG' 'RCSA' 'RCTB' 'PNDEAD' 'PNADEAD' 'PNBDEAD' 'PNCDEAD' 'PNDDEAD' 'PNEDEAD' 'PNFDEAD' 'PNGDEAD');
do i= 1 to dim(delwords1);
if GEOGN ='BRAZIL' and findw(ENAME,delwords1[i],'','eir') >0 then
delete;
end;
array delwords2 {3} $ 15 _temporary_ ('PFCL' 'PRIVILEGIADAS' 'PRVLG');
do i= 1 to dim(delwords2);
if GEOGN ='COLOMBIA' and findw(ENAME,delwords2[i],'','eir') >0 then
delete;
end;
array delwords3 {2} $ 15 _temporary_ ('PR' 'PB');
do i= 1 to dim(delwords3);
if GEOGN ='GREECE' and findw(ENAME,delwords3[i],'','eir') >0 then
delete;
end;
array delwords4 {4} $ 15 _temporary_ ('FB' 'FBDEAD' 'RTS' 'RIGHTS');
do i= 1 to dim(delwords4);
if GEOGN ='INDONESIA' and findw(ENAME,delwords4[i],'','eir') >0 then
delete;
end;
/*Around 20 arrays*/
run;
Warm regards and thanks.
You don't need arrays at all.
length DELW $15;
do DELW='PN', 'PNA', 'PNB', 'PNC', 'PND', 'PNE', 'PNF',' PNG' 'RCSA' 'RCTB' 'PNDEAD';
if GEOGN ='BRAZIL' and findw(ENAME,DELW,'eit') then delete;
end;
You don't need arrays at all.
length DELW $15;
do DELW='PN', 'PNA', 'PNB', 'PNC', 'PND', 'PNE', 'PNF',' PNG' 'RCSA' 'RCTB' 'PNDEAD';
if GEOGN ='BRAZIL' and findw(ENAME,DELW,'eit') then delete;
end;
Thank you @ChrisNZ ,
In this way, I can set up one length statement for the whole data step by using
length delwords1-delwords20 $15;
rather than list out all the length of each array.
Warm regards.
You only need one DELWORD.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.