BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil_NZ
Barite | Level 11

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.

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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;

 

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

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;

 

Phil_NZ
Barite | Level 11

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.

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1117 views
  • 2 likes
  • 2 in conversation