<?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: check if variables from a list exist in a table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788704#M252233</link>
    <description>Yes, with this approach you could break up the list.  How may "words"  do you have in your lookup list.&lt;BR /&gt;&lt;BR /&gt;Frankly if I were you I would try the proc format approach shown by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&lt;BR /&gt;It's also described in this paper, see p.2&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p102-26.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p102-26.pdf&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 06 Jan 2022 17:35:21 GMT</pubDate>
    <dc:creator>ghosh</dc:creator>
    <dc:date>2022-01-06T17:35:21Z</dc:date>
    <item>
      <title>check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788506#M252122</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to check a table against a list of variables, to identify those records in the table where any of the variables is contained.&lt;/P&gt;
&lt;P&gt;In my dummy example below, I need to identify those records in SASHELP.CARS where either "coupe", "hatch", "quattro" or "caravan" is contained in MODEL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works fine but in my real data I have about 13 million records, with about 8 million variables; SAS always times out before it completes the task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was hoping there would be a better way to do this?&lt;/P&gt;
&lt;P&gt;many thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  /*create lookup table with keys to be searched*/

data LOOKUP;
input KEY $;

datalines;
coupe
hatch
quattro
caravan
;
run;

/*create table where output will be saved*/

PROC SQL;
CREATE TABLE OUTPUT
(
MAKE char (20),
MODEL char (40)
);

%macro makereport(Var=);

/*marco loops*/

PROC SQL;
CREATE TABLE OUTPUT_AUX AS
    SELECT MAKE, MODEL
FROM SASHELP.CARS
WHERE UPPER(MODEL) contains UPPER(&amp;amp;Var);

QUIT;

/*append result to output table*/

PROC APPEND BASE=OUTPUT DATA=OUTPUT_AUX FORCE;

RUN;

%mend makereport;

data _null_;
                set WORK.LOOKUP;
                string = cats('%makereport(Var="',KEY,'");');
                call execute(string);
run;
 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 17:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788506#M252122</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2022-01-05T17:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788512#M252123</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
    CREATE TABLE OUTPUT_AUX AS SELECT MAKE, MODEL
    FROM SASHELP.CARS
    WHERE upcase(MODEL) in (select upcase(key) from lookup);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No macros needed. I can't test it on a data set that large, but 13 million records shouldn't really be problem these days. It's not clear why you mention you have 8 million variables, as those are not used in this problem at all.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 18:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788512#M252123</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-05T18:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788513#M252124</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not work though; it must be a CONTAINS rather than IN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I mentioned the 8 million to give an idea of the size (of course I cannot paste here); when I run it I get an "out of memory " type message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 18:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788513#M252124</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2022-01-05T18:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788514#M252125</link>
      <description>&lt;P&gt;Your description of "I need to identify those records in SASHELP.CARS where either "coupe", "hatch", "quattro" or "caravan" is contained in MODEL" is a "Check if VALUES" from a list exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would help to show what you expect but consider:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table found as
   select b.make, b.model
   from lookup as a, sashelp.cars as b
   where find(b.model, a.key,'i')&amp;gt;0;
run;&lt;/PRE&gt;
&lt;P&gt;The above code compares all records in the lookup data set with the SASHELP.Cars (the comma between the alias A and the Sashelp.cars data set name) and when the string of the Key in the lookup is found in the Model variable, ignoring case (the 'i' in the Find function) keeps the make and model.&lt;/P&gt;
&lt;P&gt;Note: if your KEY could possibly appear twice in a single Model you would add the Distinct predicate to the Select to get only one result per Make/model combination&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table found as
   select distinct b.make, b.model
   from lookup as a, sashelp.cars as b
   where find(b.model, a.key,'i')&amp;gt;0;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 18:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788514#M252125</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-05T18:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788519#M252128</link>
      <description>&lt;P&gt;Probably the code from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;is better, but still a Cartesian join in SQL with 13 million records may be slow. Whether it is slower than the solution I present is unknown.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
proc sql noprint;
    select quote(trim(key)) into :keys separated by ' ' from lookup;
quit;

data want;
    set sashelp.cars;
    if %do i=1 %to %sysfunc(countw(&amp;amp;keys));
        find(model,%scan(&amp;amp;keys,&amp;amp;i,%str( )),'i')&amp;gt;0
        %if &amp;amp;i&amp;lt;%sysfunc(countw(&amp;amp;keys)) %then or;
        %end;
    then output;
run;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 18:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788519#M252128</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-05T18:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788530#M252134</link>
      <description>&lt;P&gt;Maybe data step array could be solution?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data LOOKUP;
input KEY $;
datalines;
coupe
hatch
quattro
caravan
;
run;

data _null_;
  call symputX("N",nobs,"G");        
  stop;
  set lookup nobs=nobs;
run;




data want;
    /* load keys int an array */
    array lookup[&amp;amp;N.] $ 12 _temporary_;
    do _N_ = 1 by 1 until(end);
      set lookup end=end;
      lookup[_N_] = KEY; drop KEY;
    end; 

    /* loop over data set */
    do until(EOF);
      set sashelp.cars end=EOF;

      do _N_ = 1 to &amp;amp;N.;
        if find(model,lookup[_N_],'it') then 
          do; /* if model contains key do output... */
            output;
            leave; /* ...and leave the loop since there is no point to check next */
          end;
      end;
    end;

  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Everything in one data step with no macro loops.&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 19:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788530#M252134</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-05T19:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788532#M252135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321375"&gt;@MART1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not work though; it must be a CONTAINS rather than IN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I mentioned the 8 million to give an idea of the size (of course I cannot paste here); when I run it I get an "out of memory " type message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How many of the 8 million variables are actually involved in the comparison? Reduce the size to what is actually needed such as the comparison variables and enough others to uniquely identify each record. Then if needed combine that back to the original data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, how many distinct values of the comparison variables are involved?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many variables are compared to the look up values? Just how many look up values are there?&lt;/P&gt;
&lt;P&gt;And perhaps if the values of the variables aren't sensitive show some actual examples of what you are searching for in some actual values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 20:00:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788532#M252135</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-05T20:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788534#M252136</link>
      <description>&lt;P&gt;In your first line if you mean "values" rather than "variables" then the following will likely work in an 8 million record database.&amp;nbsp; A macro&amp;nbsp; variable can hold about 65K so you could fit in a large amount of values&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql noprint;                              
 select key into :to_inc separated by '|'
 from lookup;
quit;
%put &amp;amp;=to_inc;

Data want;
length match 3;
 Set sashelp.cars;
    if prxmatch("/&amp;amp;to_inc/i",model) 
 	Then MATCH=1;
 	else MATCH=0;
if match;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 20:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788534#M252136</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-01-05T20:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788543#M252143</link>
      <description>&lt;P&gt;Here's another efficient way that doesn't have the limitations of lists:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data LOOKUP;
input start $;
FmtName = '$Lookup' ;
if _n_ = 1 then do;
  HLO = 'O';
  label = 'N';
  output;
end;
HLO = '';
label = 'Y';
output;
datalines;
SEDAN
WAGON
SUV
;
run;

proc format cntlin = LOOKUP;
run;

data want;
  set SASHELP.CARS;
  where put(upcase(type), $Lookup.) = 'Y';
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 21:01:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788543#M252143</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-01-05T21:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788608#M252177</link>
      <description>&lt;P&gt;You are mixing terms, making it difficult to follow the problem description. You are talking about finding variables in dataset, but actually it seems that you want to check if one/some/all variables contain one value of list of values.&lt;/P&gt;
&lt;P&gt;To make our lives simpler, please post some observations of the data you have as working sas code (data step with datalines). The code posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt; seems to solve the problem.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 06:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788608#M252177</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-01-06T06:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788683#M252216</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the "real world", my dataset contains a list of users (column A) with their associated address (column B). The address may or may not contain the postcode. This dataset contains about 13M records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In another dataset I have a list of all UK postcodes (distinct list); it's about 8M records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is to identify those users in the first dataset who have a postcode (any postcode) in their address.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Translated to my dummy example, I wanted to find those records in CARS where model contain either "quattro" or "coupe"...&lt;/P&gt;
&lt;P&gt;If it does, the record needs to be added to the final output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have used&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763" target="_blank"&gt;@yabwon&lt;/A&gt;&amp;nbsp;code; it works perfectly if I use a small subset of the postcode, but when I use the full list (8M) it takes a long time (tried a few times but I had to&amp;nbsp; stop it after 3 hours).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe I'm just too "demanding" and this would take quite some time?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 16:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788683#M252216</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2022-01-06T16:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788684#M252217</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78622"&gt;@ghosh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;unfortunately the length of the macro exceeds 65k (maybe a can try breaking up)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 16:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788684#M252217</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2022-01-06T16:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788694#M252223</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;unfortunately the macro "keys" exceeds the maximum length (65k)&lt;BR /&gt;thanks</description>
      <pubDate>Thu, 06 Jan 2022 17:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788694#M252223</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2022-01-06T17:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788704#M252233</link>
      <description>Yes, with this approach you could break up the list.  How may "words"  do you have in your lookup list.&lt;BR /&gt;&lt;BR /&gt;Frankly if I were you I would try the proc format approach shown by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&lt;BR /&gt;It's also described in this paper, see p.2&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p102-26.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p102-26.pdf&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Jan 2022 17:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788704#M252233</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-01-06T17:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788708#M252237</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78622"&gt;@ghosh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to break it up, but in order to work it would need far too many partitions (the lookup list contains all UK postcodes, 8 M "words", each 6 or 7 digits).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll try the proc format approach (never seen it before but I'll give it a go!)&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 17:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788708#M252237</guid>
      <dc:creator>MART1</dc:creator>
      <dc:date>2022-01-06T17:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788709#M252238</link>
      <description>Some ideas for performance improvement (sorry that without details, but I'm out of town and writing from mobile):&lt;BR /&gt;1) are you able to sort dataset with codes by "town size", i.e. a postal code from London should cover bigger number of users, so if it is at the beginning of the array it should exit the do-loop faster.&lt;BR /&gt;2) try to load adres column into second array (so both data and lookup will be in memory). Array index will be pointing observation number in the dataset so you can use it in second data pass.&lt;BR /&gt;3) split lookup into several smaller datasets and run several concurrent sessions.&lt;BR /&gt;4) does the postal code have some form (e.g. 12-345) ? So you could use regexp to narrow down list of addresses.&lt;BR /&gt;&lt;BR /&gt;Bart</description>
      <pubDate>Thu, 06 Jan 2022 17:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788709#M252238</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-01-06T17:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788801#M252305</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321375"&gt;@MART1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the "real world", my dataset contains a list of users (column A) with their associated address (column B). The address may or may not contain the postcode. This dataset contains about 13M records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In another dataset I have a list of all UK postcodes (distinct list); it's about 8M records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal is to identify those users in the first dataset who have a postcode (any postcode) in their address.&lt;/P&gt;
&lt;P&gt;[...]&lt;/P&gt;
&lt;P&gt;Maybe I'm just too "demanding" and this would take quite some time?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, this will take some time. So i would not use the postcodes dataset in the first step, but a regular expression to verify that the address contains (most likely) a postcode. I am not that familiar with uk postcodes, so i can't suggest a perfect expression right know, this one may work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;.*([a-z]{1,2}\d[a-z]? \d[a-z]{2}).*&lt;/PRE&gt;
&lt;P&gt;In a second step i would load the postcode dataset into a hash object to verify that the result of the regex is an existing postcode.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 06:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788801#M252305</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-01-07T06:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788810#M252312</link>
      <description>&lt;P&gt;You can try two approaches:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;find a way to extract the postcode from the address field, so you can join with that value or use a hash object loaded from the lookup postcodes&lt;/LI&gt;
&lt;LI&gt;load the lookup postcodes into an array and loop over it to perform a FINDW or similar function for each entry&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;We would need to see complete examples for your address variable, covering all structures you have in there.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 08:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788810#M252312</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-07T08:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: check if variables from a list exist in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788819#M252318</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/321375"&gt;@MART1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "real world" explanation really helps to better understand the challenge. Some representative sample data provided via a SAS data step would likely get us even closer to your reality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code based on what I found on the Internet how UK postcodes look like:&amp;nbsp;&lt;A href="https://ideal-postcodes.co.uk/guides/uk-postcode-format" target="_blank" rel="noopener"&gt;https://ideal-postcodes.co.uk/guides/uk-postcode-format&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code syntax to extract the codes from a string based on SAS code sample from &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n1obc9u7z3225mn1npwnassehff0.htm" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code may not be fully suitable for your data but it should give you the necessary pointers ...and depending on your hardware the code should execute within minutes (or less).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...and I just realized that I've done things only for the Outward portion of the UK postcode. To change things for the full postcode shouldn't be that hard though. If you want SAS code for it then please provide representative sample data in the form of working data step code creating this data (the "users" and "postcode" tables).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data users;
  infile datalines truncover dlm='|';
  input user $ addr $40.;
  datalines;
aa|aaad bbbd 123 xxx ab3x blah
aa|aaad bbbd 2 xxx c9 blah
aa|aaad bbbd xc9 xxx  ab3x blah
aa|aaad bbbd c9 xxx  ab3x blah
aa|aaad bbbd c999 xxx  ab3xy blah
;

data postcodes;
  input postcode $;
  datalines;
ab3x
c9
;
data want;
  if _n_=1 then
    do;
      if 0 then
        set postcodes(keep=postcode);
      dcl hash h1(dataset:'postcodes');
      h1.defineKey('postcode');
      h1.defineDone();
    end;
  call missing(of _all_);

  set users;
  array postcode_candidate_ {4} $4;
  length _found $4;

  _ExpressionID = prxparse('/\b[[:alpha:]]{2}\d[[:alpha:]]\b|\b[[:alpha:]]\d[[:alpha:]]\b|\b[[:alpha:]]\d\b|\b[[:alpha:]]\d\d\b|\b[[:alpha:]]{2}\d\b|\b[[:alpha:]]{2}\d\d\b/');
  _start = 1;
  _stop = length(addr);

  /* Use PRXNEXT to find the first instance of the pattern, */
  /* then use DO WHILE to find all further instances.       */
  /* PRXNEXT changes the _start parameter so that searching  */
  /* begins again after the last match.                     */
  call prxnext(_ExpressionID, _start, _stop, addr, _position, _length);
  do while (_position &amp;gt; 0);
    _found = substr(addr, _position, _length);
    if h1.check(key:_found)=0 then
      do;
        _i=sum(_i,1);
        postcode_candidate_[_i]=_found;
      end;
    call prxnext(_ExpressionID, _start, _stop, addr, _position, _length);
  end;
  drop _:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 11:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-variables-from-a-list-exist-in-a-table/m-p/788819#M252318</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-01-07T11:05:47Z</dc:date>
    </item>
  </channel>
</rss>

