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 SAS Users,

 

I have the code below for filtering my data, it seems to work properly. However, I do not know how can it run through all observations of the variable ENAME?

So, the variable ENAME has 15,000 observations, and I want to delete any observation of which ENAME contains any word in array delwords. I do not know which code in the code below tells SAS that we go through all observations of ENAME.

 

data screen123489116    (drop=row)
     deleted (keep=row)
;
   set screen12348911;
   row=_n_;
   array delwords {84} $ 15 _temporary_ ('DUPLICATE', 'DUPL', 'DUP', 'DUPE','DULP', 'DUPLI',
'1000DUPL','XSQ','XET','ADR','GDR','PREFERRED','PF','PFD','PREF','PF','WARRANT','WARRANTS','WTS','WTS2','WARRT',
'DEB','DB','DCB','DEBT','DEBENTURES','DEBENTURE','RLST IT','INVESTMENT TRUST','INV TST','UNIT TRUST','UNT TST',
'TRUST UNITS','TST UNITS','TRUST UNIT','TST UNIT','UT','IT.','IT','500','BOND','DEFER','DEP','DEPY','ELKS','ETF','FUND','FD','IDX','INDEX','LP','MIPS','MITS','MITT','MPS','NIKKEI','NOTE',
'PERQS','PINES','PRTF','PTNS','PTSHP','QUIBS','QUIDS','RATE','RCPTS',
'RECEIPTS','REIT','RETUR','SCORE','SPDR','STRYPES','TOPRS','UNIT','UNT',
'UTS','WTS','XXXXX','YIELD','YLD','EXPIRED','EXPD','EXPIRY','EXPY');

do i= 1 to dim(delwords)until (f>0);
 f=findw(ENAME,delwords[i],'','eir');
end;
if f>0 then do;
      output deleted;
      delete;
   end;
   else output screen123489116;
run;

Many thanks and warmest 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.
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

This statement

 

   set screen12348911;

Tells the data step to read all observations from the screen12348911 data set. I think that is what you're asking.

 

Yes, correct. As the Delete Statement Documentation says: "When DELETE executes, the current observation is not written to a data set, and SAS returns immediately to the beginning of the DATA step for the next iteration." . You can leave it in for whatever little performance it may give you, but it is not necessary. All it does is return to the top of the data step, which happens anyways at the bottom of the data step.

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

I just made a few comments. Hope the code makes more sense now. Feel free to ask 🙂

 

data screen123489116    (drop=row)
     deleted (keep=row)
;
   set screen12348911;
   row=_n_;
   array delwords {84} $ 15 _temporary_ ('DUPLICATE', 'DUPL', 'DUP', 'DUPE','DULP', 'DUPLI',
'1000DUPL','XSQ','XET','ADR','GDR','PREFERRED','PF','PFD','PREF','PF','WARRANT','WARRANTS','WTS','WTS2','WARRT',
'DEB','DB','DCB','DEBT','DEBENTURES','DEBENTURE','RLST IT','INVESTMENT TRUST','INV TST','UNIT TRUST','UNT TST',
'TRUST UNITS','TST UNITS','TRUST UNIT','TST UNIT','UT','IT.','IT','500','BOND','DEFER','DEP','DEPY','ELKS','ETF','FUND','FD','IDX','INDEX','LP','MIPS','MITS','MITT','MPS','NIKKEI','NOTE',
'PERQS','PINES','PRTF','PTNS','PTSHP','QUIBS','QUIDS','RATE','RCPTS',
'RECEIPTS','REIT','RETUR','SCORE','SPDR','STRYPES','TOPRS','UNIT','UNT',
'UTS','WTS','XXXXX','YIELD','YLD','EXPIRED','EXPD','EXPIRY','EXPY');

do i= 1 to dim(delwords) until (f>0);       /* Iterate through the array until f > 0 (ENAME Contains the word)                                  */
 f=findw(ENAME,delwords[i],'','eir');       /* Set f equal to the position of the current word in the array in ENAME. If it is not there, f = 0 */
end;

if f>0 then do;                             /* If f > 0 (The word is in ENAME, do this                                  */
      output deleted;                       /* Output the observation to the deleted data set                           */
      delete;                               /* Go to the top of the data step (Strictly, you do not need this statement */
   end;

   else output screen123489116;             /* If f = 0 (The word is NOT in ENAME, do this                              */
run;
Phil_NZ
Barite | Level 11

Hi @PeterClemmensen 

Thank you very much for your note, I understand the meaning of the code! However, my point here is, which line of code of the code above tells SAS that we need to run through all observations of ENAME (from 1 to 15000) ?

 

And it is quite interesting about this code

delete;                               /* Go to the top of the data step (Strictly, you do not need this statement */

So, you mean the code I wrote, if the observation contains the word in array, it will be written in output "deleted", if not, it will be written in "screen123489116", so we do not need to delete this observation, am I correct?

 

Many thanks and warmest 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.
PeterClemmensen
Tourmaline | Level 20

This statement

 

   set screen12348911;

Tells the data step to read all observations from the screen12348911 data set. I think that is what you're asking.

 

Yes, correct. As the Delete Statement Documentation says: "When DELETE executes, the current observation is not written to a data set, and SAS returns immediately to the beginning of the DATA step for the next iteration." . You can leave it in for whatever little performance it may give you, but it is not necessary. All it does is return to the top of the data step, which happens anyways at the bottom of the data step.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 655 views
  • 2 likes
  • 2 in conversation