SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
buddha_d
Pyrite | Level 9

 

proc sql;
create table WORK.have( bufsize=65536 )
  (
   acct_nbr char(150) format=$150. informat=$150. label='acct_number',
   Acct_NAME char(150),
   cust_name1 char(150),
   cust_name2 char(150),
   first_name char(150),
   middle_name char(150),
   last_name char(150)
  );

insert into WORK.have
values('54321', 'BUTSCH FAITH', 'PETER R BUTSCH', '', 'PETER', 'RAY', 'BUTSCH' )
values('54321', 'BUTSCH PETER', 'FAITH F BUTSCH', '', 'FAITH', 'FINN', 'BUTSCH' )
values('54321', 'FAITH BUTSCH', 'PETER R BUTSCH', '', 'PETER', 'RIVER', 'BUTSCH' )
values('54321', 'FINN BUTSCH', 'PETER R BUTSCH', '', 'PETER', 'RIVER', 'BUTSCH' )
values('54321', 'BUTSCH RAY', 'PETER R BUTSCH', '', 'PETER', 'RIVER', 'BUTSCH' )
values('54321', 'RAY PETER', 'PETER R BUTSCH', '', 'PETER', 'RIVER', 'BUTSCH' )
values('54321', 'MARY JAY RICHARDSON', 'FAITH F BUTSCH', '', 'FAITH', 'FINN', 'BUTSCH' )
values('12345', 'DONALD W WICK', 'NANCY DIANE WICK','', 'NANCY', 'DIANE','WICK')
values('12345', 'DONALD WICK', 'NANCY DIANE WICK','', 'NANCY', 'DIANE', 'WICK')
values('12345', 'NANCY WICK',	'DONALD W WICK','','DONALD','W','WICK')
;
quit;

I have the above data. This is the sample data and I need to filter data based on acct_name field with first_name, middle_name and last_name fields. You could use other fields as well. But, what I need to see is the record where acct_name is totally different from any first_name, middle_name and last_name. 

 

The output should look like :

 

acct_nbr Acct_NAME cust_name1 cust_name2 first_name middle_name last_name
54321 MARY JAY RICHARDSON FAITH F BUTSCH FAITH FINN BUTSCH
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12
data want;
  set have;
  array names{5} cust_name1 cust_name2 first_name middle_name last_name;
  do i=1 to dim(names);
    index=find(Acct_NAME,names{i},'IT');
    if index>0 then delete;
  end;
  drop i;
run;

View solution in original post

4 REPLIES 4
japelin
Rhodochrosite | Level 12
data want;
  set have;
  array names{5} cust_name1 cust_name2 first_name middle_name last_name;
  do i=1 to dim(names);
    index=find(Acct_NAME,names{i},'IT');
    if index>0 then delete;
  end;
  drop i;
run;
buddha_d
Pyrite | Level 9
Japelin, your code works for me. Thanks for sharing the logic.
s_lassen
Meteorite | Level 14

You could try something like this:

proc sql;
  create table want as select * from have
  where not indexw(Acct_NAME,first_name) 
    and not indexw(Acct_NAME,middle_name) 
    and not indexw(Acct_NAME,last_name) ;

The solution is similar to the datastep shown by @japelin , but it does not check CUST_NAME1-2, as you did not mention those, and it checks if the first/middle/last name occurs as a word in ACCT_NAME (assuming that you want records like 'WALTER ROBINSON' vs. 'ROBIN', 'T', 'HENDRICKS', - ROBIN should not match ROBINSON) by using the INDEXW function.

buddha_d
Pyrite | Level 9
S_lassen, your logic works for me as well. Thank you so much for sharing.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 4 replies
  • 1271 views
  • 2 likes
  • 3 in conversation