<?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: Hash tables - find code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803065#M316213</link>
    <description>&lt;P&gt;I don't understand . Hash Table perform the exact match . If you want fuzz match , try other way like PRX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
length id $10 dcode $48;
input id$ dcode$ &amp;amp;;
datalines;
1 I410 J332
2 C450 I412
3 I413 R789
4 R281 I519
5 O603 C351
;
run;

data want;
 set have;
 if prxmatch('/\b(I41|I51)/i',dcode);
 run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 21 Mar 2022 12:50:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-03-21T12:50:24Z</dc:date>
    <item>
      <title>Hash tables - find code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803063#M316211</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using the script below to find certain codes in a very large dataset with hash-tables. Now I have to write the exact code for the dcode I would like to find (e.g: 'I412' or 'I519') for the scan-function. Instead I would like to find every code that starts with 'I41' or 'I51' with the help of hash-tables using&amp;nbsp;&lt;SPAN&gt;colon (:) modifier?&lt;/SPAN&gt;&amp;nbsp;Is that possible?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;length id $10 dcode $48;&lt;BR /&gt;input id$ dcode$ &amp;amp;;&lt;BR /&gt;datalines;&lt;BR /&gt;1 I410 J332&lt;BR /&gt;2 C450 I412 &lt;BR /&gt;3 I413 R789&lt;BR /&gt;4 R281 I519&lt;BR /&gt;5 O603 C351&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data Codes;&lt;BR /&gt;length code $4.;&lt;BR /&gt;input code $ ;&lt;BR /&gt;datalines; &lt;BR /&gt;I410&lt;BR /&gt;I412&lt;BR /&gt;I413&lt;BR /&gt;I519&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;DATA Code_scan;&lt;BR /&gt;length code $4.;&lt;/P&gt;
&lt;P&gt;if _N_=1 then do;&lt;/P&gt;
&lt;P&gt;declare hash P(dataset: 'Codes');&lt;BR /&gt;P.defineKey('code');&lt;BR /&gt;P.defineData('code');&lt;BR /&gt;P.defineDone();&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;set&lt;/P&gt;
&lt;P&gt;have&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;length Findcode $4;&lt;/P&gt;
&lt;P&gt;do i=1 to 30 by 1;&lt;BR /&gt;Findcode=scan(Dcode,i,'');&lt;BR /&gt;if Findcode='' then leave;&lt;BR /&gt;if P.find(key:Findcode) = 0&lt;BR /&gt;then do;&lt;BR /&gt;output;&lt;BR /&gt;leave;&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 12:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803063#M316211</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2022-03-21T12:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables - find code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803065#M316213</link>
      <description>&lt;P&gt;I don't understand . Hash Table perform the exact match . If you want fuzz match , try other way like PRX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
length id $10 dcode $48;
input id$ dcode$ &amp;amp;;
datalines;
1 I410 J332
2 C450 I412
3 I413 R789
4 R281 I519
5 O603 C351
;
run;

data want;
 set have;
 if prxmatch('/\b(I41|I51)/i',dcode);
 run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 12:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803065#M316213</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-21T12:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables - find code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803067#M316215</link>
      <description>&lt;P&gt;Here's another Perl Regular Expression example, I basically hacked this &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n1obc9u7z3225mn1npwnassehff0.htm" target="_self"&gt;example&lt;/A&gt; in the documentation&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length id $10 dcode $48;
	input id$ dcode$ &amp;amp;;
datalines;
1 I410 J332
2 C450 I412
3 I413 R789 I412 I4123
4 R281 I519 I413 I51698
5 O603 C351 
;
run;

data want ;
	retain re 0 ;
	if _n_=1 then do ;
		re=prxparse('/I41\w*|I51\w*/') ;
	end ;
	set have ;
	x=prxmatch(re,dcode) ;
	start=1 ;
	stop=length(dcode) ;
	call prxnext(re,start,stop,dcode,position,length) ;
	do while(position&amp;gt;0) ;
		found=substr(dcode,position,length) ;
		call prxnext(re,start,stop,dcode,position,length) ;
		put found= ;
		output ;
	end ;
run ;

	
	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 13:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803067#M316215</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-03-21T13:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables - find code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803068#M316216</link>
      <description>&lt;P&gt;I use hash-tables to save time - so I would really like to use hash-tables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 13:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803068#M316216</guid>
      <dc:creator>Chris_LK_87</dc:creator>
      <dc:date>2022-03-21T13:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Hash tables - find code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803082#M316221</link>
      <description>&lt;P&gt;I checked with a colleague who handles the hash object and you can't use a wild card, still there are other ways and this one works.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length id $10 dcode $48;
	input id$ dcode$ &amp;amp;;
datalines;
1 I410 J332
2 C450 I412
3 I413 R789
4 R281 I519
5 O603 C351
6 3456 I510
7 I444 2345
8 I418 6789
9 I509 1234
10 9876 I412
;
run;



data Codes;
	length code $4.;
	input code $ ;
datalines;
I410
I412
I413
I519
;
run;
data tmp;
	set codes;
	chk=substr(code,1,3);
run;


DATA Code_scan;
	length chk $3.;
	if _N_=1 then do;
		declare hash P(dataset: 'tmp');
		P.defineKey('chk');
		P.defineData('chk');
		P.defineDone();
	end;
	set have ;
	length Findcode $4;
	do i=1 to 30 by 1;
		Findcode=substr(scan(Dcode,i,''),1,3);
		if Findcode='' then leave;
		if P.find(key:Findcode) = 0
		then do;
			output;
			leave;
		end;
	end;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 14:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-tables-find-code/m-p/803082#M316221</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-03-21T14:29:20Z</dc:date>
    </item>
  </channel>
</rss>

