<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Filtering data based on two columns with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/816048#M322069</link>
    <description>&lt;P&gt;ChrisNZ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; It is working for the records that have middle name, but if the middle name is missing then it is not picking the period in the end. For example:&lt;/P&gt;&lt;P&gt;Below example doesn't have middle name. So the str2 should have DO...0V4. but it shows as DO...0V4.&amp;nbsp; How can we fix it please?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;M....0V4.&lt;/TD&gt;&lt;TD&gt;VUING DO/5595/&lt;/TD&gt;&lt;TD&gt;DO...0V4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Wed, 01 Jun 2022 16:39:15 GMT</pubDate>
    <dc:creator>buddha_d</dc:creator>
    <dc:date>2022-06-01T16:39:15Z</dc:date>
    <item>
      <title>Filtering data based on two columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815440#M321870</link>
      <description>&lt;P&gt;I have a dataset which has account IDs (acct_id) and Account Names (acct_name). I have a pattern to figure out if the account exactly&amp;nbsp;belongs to a customer. There are suffixes like JR or SR or I or V or MD which I don't need to take it to account for account name. I made up the data that almost matches my original data.&lt;BR /&gt;For example:&lt;BR /&gt;MICHAEL D KUELKAR JR Account Name has account id of KUELK2M6D.&lt;BR /&gt;The account ID is calculated like below&lt;BR /&gt;first 5 letters of last name (KUELK)+how many more letters are left in the last name (2 more letters, AR in this case)+&lt;BR /&gt;first letter of the first name(M as in Michael)+how many letters are left after the first letter of the first name (ICHAEL, 6 Letters)+first letter of middle name (D in this case)&lt;/P&gt;&lt;P&gt;If there are any last name are lower than 5 bytes (length less than 5), there will be periods (like .). Since the length of the last name is&amp;nbsp;less than 5 letter, there will not be any letters left so we have 0 after the last name and periods.&lt;BR /&gt;If the middle name is missing then you would have . as well.&lt;BR /&gt;Like acct_name (PING-PONG LI/2121/) acct_id is LI...0P3P&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I need to find the mismatch acct_name and acct_id.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Here is the code I tried, Please suggest me how to go forward from here. Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
create table WORK.HAVE ( bufsize=65536 )
  (
   acct_id char(27),
   acct_name char(240)
  );
QUIT;
PROC SQL;
INSERT INTO have
VALUES ("KING.0R6K","RICHARD K KING JR/1111/")
VALUES ("KO...0C4.","CAMEY JOE/2282/")
VALUES ("KUELK2M6D","MICHAEL D KUELKAR JR/1110/")
VALUES ("FUSS.0J4.","JACOB JOHN FUSS VI/8889/")
VALUES ("LI...0P3P", "PING-PONG LI/2121/")
VALUES ("LO...0T6Z","TSARA YEU ZEE LO/6666/")
VALUES ("LOYD.0W5.","WESLEY BRUCE LOYD SR/1181/")
VALUES ("LUCER7M4.","MARIA K LUCERA SR/3333/")
VALUES ("BUCKE2W0K","WK BUCKETT JR/1151/")
VALUES ("LUM..0R5H","ROBERTS H S/1141/")
VALUES ("M....0V4.","VUING DO/5595/")
VALUES ("MILLS0S4C","STEVE MILLS IV/9898/")
VALUES ("SUTTE1D3.","DARK N SUTTER M D/3331/")
VALUES ("ATKIN1R5D","ROBERT ATKINS SR/5656/")
VALUES ("ATKIN1R5D","ROBERT D ATKINS SR/1212/")
VALUES ("ANGUI9G7.","GAMELIEL S ANGUIAND SR/1897/")
VALUES ("ARNIT1J5M","JESSIE M ARNITT JR/4564/")
VALUES ("DAXTE1F4L","FRANK LEVIS DAXTER V/6781/")
VALUES ("BEASO1R2S","RON SHARE BEASON II/9872/")
VALUES ("CASTI6A8Z","ALEXA Z CASTILLEMOS SR/9861/")
VALUES ("CESTR1G6C","GERARDI CAMACHO-CESTRO IV/5671/")
VALUES ("BROWN0J5.","JACKIE BROWN M D/5671/")
VALUES ("CRAPS2D5J","CRAPSEN DIANIA JOE/0981/")
VALUES ("DEBAR6M4H","MERCY H DEE/0001/")
VALUES ("DEDIO1F4R","FELEX V DEDIOS JR/0001/")
VALUES ("KRIEK6S3T","SEAN THOMAS KREIKEMAIAR/0001/")
VALUES ("CASTR1G6C","GERARDI CAMACHI-CASTRO IV/0001/")
;
QUIT;


	
DATA HAVE;
	SET HAVE;
	NEW_VAR=SCAN(acct_name,1,'/');
RUN;


data want ;
  set have;
  do i=1 to countw(new_var,' ');
     var1=scan(new_var,i,' ');
     output;
  end;
  drop i new_var ;
run;

proc sql;
	create table want1 as
	select *
	from want 
	where acct_id not in  
	(select distinct acct_id 
	from want 
	where strip(compress(substr(acct_id,1,5),,'p')) in (select var1 from want) )

;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 17:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815440#M321870</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-05-27T17:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on two columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815494#M321891</link>
      <description>&lt;P&gt;The output should have the below records only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;acct_id acct_name&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;KO...0C4. CAMEY JOE/2282/&lt;BR /&gt;LO...0T6Z TSARA YEU ZEE LO/6666/&lt;BR /&gt;LOYD.0W5. WESLEY BRUCE LOYD SR/1181/&lt;BR /&gt;LUCER7M4. MARIA K LUCERA SR/3333/&lt;BR /&gt;LUM..0R5H ROBERTS H S/1141/&lt;BR /&gt;M....0V4. VUING DO/5595/&lt;BR /&gt;MILLS0S4C STEVE MILLS IV/9898/&lt;BR /&gt;SUTTE1D3. DARK N SUTTER M D/3331/&lt;BR /&gt;ATKIN1R5D ROBERT ATKINS SR/5656/&lt;BR /&gt;ANGUI9G7. GAMELIEL S ANGUIAND SR/1897/&lt;BR /&gt;CASTI6A8Z ALEXA Z CASTILLEMOS SR/9861/&lt;BR /&gt;DEBAR6M4H MERCY H DEE/0001/&lt;BR /&gt;DEDIO1F4R FELEX V DEDIOS JR/0001/&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 20:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815494#M321891</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-05-27T20:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on two columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815658#M321936</link>
      <description>&lt;P&gt;Thank you for providing usable data, even if it seems imperfect.&lt;/P&gt;
&lt;P&gt;This should get you started:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT ;
 set HAVE;
  STR=scan(ACCT_NAME,1,'/'); 
  STR=prxchange('s/\b(I|V|MD|JR|SR|M|II)\b//',-1,STR); 
  FN =scan(STR,1);
  N2 =scan(STR,2);
  N3 =scan(STR,3);
  if N3 ne ' ' then do;
    LN=N3;
    MN=N2;
  end;
  else LN=N2;
  STR2=cats(substr(LN,1,5)
           ,substrn('....',1,5-length(LN))
           ,max(length(LN)-5,0)
           ,first(FN)
           ,length(FN)-1
           ,first(MN||'.')
           ); 
  if STR2 ne ACCT_ID;
run;    

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV&gt;
&lt;DIV id="IDX"&gt;
&lt;TABLE class="table" aria-label="Data Set WORK.WANT"&gt;&lt;CAPTION aria-label="Data Set WORK.WANT"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;acct_id&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;acct_name&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;STR2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="data"&gt;KO...0C4.&lt;/TD&gt;
&lt;TD class="data"&gt;CAMEY JOE/2282/&lt;/TD&gt;
&lt;TD class="data"&gt;JOE..0C4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="data"&gt;FUSS.0J4.&lt;/TD&gt;
&lt;TD class="data"&gt;JACOB JOHN FUSS VI/8889/&lt;/TD&gt;
&lt;TD class="data"&gt;FUSS.0J4J&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="data"&gt;LO...0T6Z&lt;/TD&gt;
&lt;TD class="data"&gt;TSARA YEU ZEE LO/6666/&lt;/TD&gt;
&lt;TD class="data"&gt;ZEE..0T4Y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="data"&gt;LOYD.0W5.&lt;/TD&gt;
&lt;TD class="data"&gt;WESLEY BRUCE LOYD SR/1181/&lt;/TD&gt;
&lt;TD class="data"&gt;LOYD.0W5B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="data"&gt;LUCER7M4.&lt;/TD&gt;
&lt;TD class="data"&gt;MARIA K LUCERA SR/3333/&lt;/TD&gt;
&lt;TD class="data"&gt;LUCER1M4K&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="data"&gt;BUCKE2W0K&lt;/TD&gt;
&lt;TD class="data"&gt;WK BUCKETT JR/1151/&lt;/TD&gt;
&lt;TD class="data"&gt;BUCKE2W1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="data"&gt;LUM..0R5H&lt;/TD&gt;
&lt;TD class="data"&gt;ROBERTS H S/1141/&lt;/TD&gt;
&lt;TD class="data"&gt;S....0R6H&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="data"&gt;M....0V4.&lt;/TD&gt;
&lt;TD class="data"&gt;VUING DO/5595/&lt;/TD&gt;
&lt;TD class="data"&gt;DO...0V4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="data"&gt;MILLS0S4C&lt;/TD&gt;
&lt;TD class="data"&gt;STEVE MILLS IV/9898/&lt;/TD&gt;
&lt;TD class="data"&gt;IV...0S4M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="data"&gt;SUTTE1D3.&lt;/TD&gt;
&lt;TD class="data"&gt;DARK N SUTTER M D/3331/&lt;/TD&gt;
&lt;TD class="data"&gt;SUTTE1D3N&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TD class="data"&gt;ATKIN1R5D&lt;/TD&gt;
&lt;TD class="data"&gt;ROBERT ATKINS SR/5656/&lt;/TD&gt;
&lt;TD class="data"&gt;ATKIN1R5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TD class="data"&gt;ANGUI9G7.&lt;/TD&gt;
&lt;TD class="data"&gt;GAMELIEL S ANGUIAND SR/1897/&lt;/TD&gt;
&lt;TD class="data"&gt;ANGUI3G7S&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TD class="data"&gt;ARNIT1J5M&lt;/TD&gt;
&lt;TD class="data"&gt;JESSIE M ARNITT JR/4564/&lt;/TD&gt;
&lt;TD class="data"&gt;ARNIT1J5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;14&lt;/TH&gt;
&lt;TD class="data"&gt;CASTI6A8Z&lt;/TD&gt;
&lt;TD class="data"&gt;ALEXA Z CASTILLEMOS SR/9861/&lt;/TD&gt;
&lt;TD class="data"&gt;CASTI6A4Z&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;15&lt;/TH&gt;
&lt;TD class="data"&gt;BROWN0J5.&lt;/TD&gt;
&lt;TD class="data"&gt;JACKIE BROWN M D/5671/&lt;/TD&gt;
&lt;TD class="data"&gt;D....0J5B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;16&lt;/TH&gt;
&lt;TD class="data"&gt;CRAPS2D5J&lt;/TD&gt;
&lt;TD class="data"&gt;CRAPSEN DIANIA JOE/0981/&lt;/TD&gt;
&lt;TD class="data"&gt;JOE..0C6D&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;17&lt;/TH&gt;
&lt;TD class="data"&gt;DEBAR6M4H&lt;/TD&gt;
&lt;TD class="data"&gt;MERCY H DEE/0001/&lt;/TD&gt;
&lt;TD class="data"&gt;DEE..0M4H&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;18&lt;/TH&gt;
&lt;TD class="data"&gt;DEDIO1F4R&lt;/TD&gt;
&lt;TD class="data"&gt;FELEX V DEDIOS JR/0001/&lt;/TD&gt;
&lt;TD class="data"&gt;DEDIO1F4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;19&lt;/TH&gt;
&lt;TD class="data"&gt;KRIEK6S3T&lt;/TD&gt;
&lt;TD class="data"&gt;SEAN THOMAS KREIKEMAIAR/0001/&lt;/TD&gt;
&lt;TD class="data"&gt;KREIK6S3T&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 30 May 2022 08:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815658#M321936</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-05-30T08:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on two columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815720#M321962</link>
      <description>ChrisNZ,&lt;BR /&gt;This would definitely a good starting point for my project. Thanks for your help.</description>
      <pubDate>Mon, 30 May 2022 16:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/815720#M321962</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-05-30T16:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on two columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/816048#M322069</link>
      <description>&lt;P&gt;ChrisNZ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; It is working for the records that have middle name, but if the middle name is missing then it is not picking the period in the end. For example:&lt;/P&gt;&lt;P&gt;Below example doesn't have middle name. So the str2 should have DO...0V4. but it shows as DO...0V4.&amp;nbsp; How can we fix it please?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;M....0V4.&lt;/TD&gt;&lt;TD&gt;VUING DO/5595/&lt;/TD&gt;&lt;TD&gt;DO...0V4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 01 Jun 2022 16:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/816048#M322069</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-06-01T16:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on two columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/816486#M322289</link>
      <description>&lt;P&gt;Replace&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;,first(MN||'.')&lt;/LI-CODE&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;,coalecsec(first(MN),'.')&lt;/LI-CODE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 06:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/816486#M322289</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-06-04T06:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering data based on two columns with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/816656#M322363</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961" target="_blank" rel="noopener"&gt;ChrisNZ&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Thanks for the idea. It works as per the logic. I appreciate your help.&amp;nbsp;&lt;BR /&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 15:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filtering-data-based-on-two-columns-with-conditions/m-p/816656#M322363</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-06-06T15:31:46Z</dc:date>
    </item>
  </channel>
</rss>

