<?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: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323623#M71762</link>
    <description>&lt;P&gt;Well, the simplest way, as you have two sets of values - again, there are various different ways - can be found below.&lt;/P&gt;
&lt;P&gt;Edit, included a plain Base SAS example further below which shows data modelling change, merging and arrays to achieve the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data colour_text;
  input text $char38.;
datalines;
i want a BLUE BALL please
did you see a blue car go by
i have owned a yellow yacht before
id never buy a red ball
we want a turqoise car
she said it was a yellow plane toy
he drove in his green Porsche
i didnt like his black heart
he had a grey ball
i saw a white plane
;
run;

data colours;
  input name $char10.;
datalines;
BLUE
YELLOW
GREEN
RED
BLACK
WHITE
;
run;

data types;
  input type $char15.;
datalines;
CAR
BALL
YACHT
;
run;

data _null_;
  set colours end=last;
  if _n_=1 then call execute('data want; set colour_text;');
  call execute(cats('if found &amp;lt; 1 then found=index(upcase(text),"',name,'");'));
  if last then call execute('run;');
run;

data _null_;
  set types end=last;
  if _n_=1 then call execute('data want; set want;');
  call execute(cats('if found2 &amp;lt; 1 then found2=index(upcase(text),"',type,'");'));
  if last then call execute('run;');
run;

data want (drop=found found2);
  set want (where=(found &amp;gt; 0 and found2 &amp;gt; 0));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* Note same test data as above */
data types;
  input type $char15.;
datalines;
CAR
BALL
YACHT
;
run;

proc transpose data=colours out=t_colors prefix=c;
  var name;
run;
proc transpose data=types out=t_types prefix=t;
  var type;
run;
data total;
  merge t_colors t_types;
run;

proc sql;
  create table WANT as
  select  A.*,
          B.*
  from    COLOUR_TEXT A
  left join TOTAL B
  on      1=1;
quit;

data want (keep=text);
  set want;
  array c c:;
  array t t:;
  do i=1 to dim(c);
    if findw(upcase(text),strip(c{i})) then found=sum(found,1);
  end;
  do i=1 to dim(t);
    if findw(upcase(text),strip(t{i})) then found2=sum(found2,1);
  end;
  if found &amp;gt; 0 and found2 &amp;gt; 0 then output;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Jan 2017 14:22:47 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-01-10T14:22:47Z</dc:date>
    <item>
      <title>Storing a list of values (from a dataset) in a macro variable to use in a regular expression search</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323574#M71738</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a newbie to creating macro's i was hoping for a tad of help if you please:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to identify certain text that meets conditions, one being that i have an extensive list of values in a dataset that are "keywords" as such.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rather than using %let Colour = 'BLUE' 'RED' etc , i was hoping to compile a macro that would look at each value individually (from a list of 1000plus entries on a dataset)&amp;nbsp;against a seperate piece of text data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is an example below using colours, where i want to match using regular expressions (ideal&amp;nbsp;for my actual process) to look for the colour plus car , ball or yacht.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below example is wrong as i know it gives me a varlist value of all of the colours in row, where im hoping a macro could simply give me a reference for all values (it looks at each value individually). I'm probably leaning towards a %do loop method but my attempts thus far are miserable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Colour_text;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; text &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$CHAR38.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;i want a BLUE BALL&lt;/P&gt;&lt;P&gt;did you see a blue car&lt;/P&gt;&lt;P&gt;i have owned a yellow yacht&lt;/P&gt;&lt;P&gt;id never buy a red ball&lt;/P&gt;&lt;P&gt;we want a turqoise car&lt;/P&gt;&lt;P&gt;she said it was a yellow plane&lt;/P&gt;&lt;P&gt;he drove in his green Porsche&lt;/P&gt;&lt;P&gt;i didnt like his black heart&lt;/P&gt;&lt;P&gt;he had a grey ball&lt;/P&gt;&lt;P&gt;i saw a white plane&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/*could be a list of 1000 plus entries*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Colours;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NAME &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$CHAR10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;BLUE&lt;/P&gt;&lt;P&gt;YELLOW&lt;/P&gt;&lt;P&gt;GREEN&lt;/P&gt;&lt;P&gt;RED&lt;/P&gt;&lt;P&gt;BLACK&lt;/P&gt;&lt;P&gt;WHITE&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/*macro required*/&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; allcolours $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1000&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; allcolours ' ';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Colours &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=eof;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;allcolours = trim(left(allcolours))||' '||left(NAME);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; eof &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput('varlist', allcolours);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;varlist;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/*identify only colours from the colour list with the trailing words car/ball/yacht */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; WHAT_I_want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; colour_text;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; prxmatch("/[a-z]*&amp;amp;varlist;([a-z]| car| ball| yacht)/i",text);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 11:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323574#M71738</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T11:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323580#M71741</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give a look at my last solution proposal on this topic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Hide-the-name-inside-the-text/m-p/321836#U321836" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Hide-the-name-inside-the-text/m-p/321836#U321836&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's exactly what you need, just remove the masking code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 11:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323580#M71741</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-10T11:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323591#M71746</link>
      <description>&lt;P&gt;This bit of code adds found and found2 to color_text and saves to dataset want:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set colours end=last;
  if _n_=1 then call execute('data want; set colour_text;');
  call execute(cats('if index(upcase(text),"',name,'") &amp;gt; 0 then found=1;'));
  if last then call execute('if scan(reverse(text),1," ") in ("rac","llab","thcay") then found2=1;run;');
run;
&lt;/PRE&gt;
&lt;P&gt;What this does is, by using the second dataset, generate the code necessary to parse the first and add in the flags. &amp;nbsp;If you un it and look at the log you will see the generated code looks like:&lt;/P&gt;
&lt;PRE&gt;NOTE: CALL EXECUTE generated line.
1     + data want; set colour_text;
2     + if index(upcase(text),"BLUE") &amp;gt; 0 then found=1;
3     + if index(upcase(text),"YELLOW") &amp;gt; 0 then found=1;
4     + if index(upcase(text),"GREEN") &amp;gt; 0 then found=1;
5     + if index(upcase(text),"RED") &amp;gt; 0 then found=1;
6     + if index(upcase(text),"BLACK") &amp;gt; 0 then found=1;
7     + if index(upcase(text),"WHITE") &amp;gt; 0 then found=1;
8     + if scan(reverse(text),1," ") in ("rac","llab","thcay") then found2=1;run;

NOTE: There were 10 observations read from the data set WORK.COLOUR_TEXT.
&lt;/PRE&gt;
&lt;P&gt;Do note however, it is a more advanced topic, not sure how good your knowledge of Base SAS is - remember macro and code generation are only there to help, they are not a replacement for Base SAS. &amp;nbsp;For instance your problem could also be solved by merging colours onto colour_text, based on finding the string within the list or transposing the colors:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=colours out=t_colours;
  var name;
run;

proc sql;
  create table WANT as
  select  A.*,
          B.*
  from    COLOUR_TEXT A
  left join T_COLOURS B
  on      1=1;
quit;

data want;
  set want;
  array col col:;
  do i=1 to dim(col);
    if found=0 then found=findw(upcase(text),strip(col{i}));
  end;
run;&lt;/PRE&gt;
&lt;P&gt;There are various methods.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 12:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323591#M71746</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-10T12:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323593#M71748</link>
      <description>&lt;P&gt;Hi DanielSantos,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for the prompt response - i applied the logic you used previously and adjusted to my query ,removing the masks, but receive nil results - are you able to see why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i also tried the IF clause you had, but that brought back all results, (as it would without including a clause for yacht car etc as in my reg exp)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Colours;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput('NAMES',catx(' ',symget('NAMES'),upcase(NAME)));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NAMES=&amp;amp;NAMES;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _WORD $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;200&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; _SEP $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Colour_text;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _:; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;* drop aux vars;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;_text=text; _text=''; _SEP=''; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;* init aux vars;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;* process one word;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _I=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; countw(text);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;_text=catx(_SEP,_text,_WORD);&lt;/P&gt;&lt;P&gt;_WORD=scan(text,_I,' ');&lt;/P&gt;&lt;P&gt;/* * if match, mask word; */&lt;/P&gt;&lt;P&gt;/**/&lt;/P&gt;&lt;P&gt;/* if index(" &amp;amp;NAMES ",cat(' ',strip(upcase(_WORD)),' ')) then do;*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; prxmatch("/[a-z]*&amp;amp;NAMES;([a-z]| car| ball| yacht)/i",text) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;OUTPUT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/* _WORD=repeat('X',lengthn(_WORD)-1);*/&lt;/P&gt;&lt;P&gt;/* _SEP='X'; */&lt;/P&gt;&lt;P&gt;/* end;*/&lt;/P&gt;&lt;P&gt;/* else _SEP=' '; * clear masking separator;*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;text=catx(_SEP,_text,_WORD);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 12:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323593#M71748</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T12:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323597#M71749</link>
      <description>&lt;P&gt;Hi RW9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;whilst that is a interesting and useful approach, it still does not give me the output im after ,i.e it does not show those with just the values i require. ideally i would like to keep this within a macro also, but do appreciate the alternative approach&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;text&amp;nbsp;_NAME_&amp;nbsp;COL1&amp;nbsp;COL2&amp;nbsp;COL3&amp;nbsp;COL4&amp;nbsp;COL5&amp;nbsp;COL6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; i&amp;nbsp;&amp;nbsp; found&lt;BR /&gt;i want a BLUE BALL&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;BR /&gt;did you see a blue car&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;BR /&gt;i have owned a yellow yacht&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;7&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;BR /&gt;id never buy a red ball&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;BR /&gt;we want a turqoise car&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;.&lt;BR /&gt;she said it was a yellow plane&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;7&amp;nbsp;.&lt;BR /&gt;he drove in his green Porsche&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;7&amp;nbsp;.&lt;BR /&gt;i didnt like his black heart&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;7&amp;nbsp;.&lt;BR /&gt;he had a grey ball&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;7&amp;nbsp;.&lt;BR /&gt;i saw a white plane&amp;nbsp;NAME&amp;nbsp;BLUE&amp;nbsp;YELLOW&amp;nbsp;GREEN&amp;nbsp;RED&amp;nbsp;BLACK&amp;nbsp;WHITE&amp;nbsp;7&amp;nbsp;.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 12:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323597#M71749</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T12:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323598#M71750</link>
      <description>&lt;P&gt;Not sure how the example above doesn't give the results you want? &amp;nbsp;Perhaps you mean you would rather the output dataset just had those observations where the calculated FOUND flag was not zero? &amp;nbsp; If so just add an appropriate condition output (or delete) statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro code is only useful for generating code. It is not too useful for manipulating data. Your problem is really about comparing two sets of DATA so the real problem is to find SAS code that solves the problem. Then you can see if macro logic can help you generate that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But be aware of the limits of SAS strings. Variables (like the regular expression in your original post) can only be 32K long. So a long list of text values to find might exceed that limit. &amp;nbsp;Similarly macro variables are limited to 64K. &amp;nbsp;So a method like above that uses multiple variables to store the strings or one that uses multiple observations is probably the one that will give you general solution that will work for future sets of keywords and strings.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 12:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323598#M71750</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-01-10T12:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323603#M71752</link>
      <description>&lt;P&gt;Just a couple of points, the data _null_ approach is not really any different to macro, it is merely generating the text which gets included as code later on. &amp;nbsp;It can be changed in anyway you want, just change:&lt;/P&gt;
&lt;PRE&gt;  if last then call execute('if scan(reverse(text),1," ") in ("rac","llab","thcay") then found2=1;run;');
&lt;/PRE&gt;
&lt;P&gt;To something appropriate to your requirements:&lt;/P&gt;
&lt;PRE&gt;  if last then call execute('if scan(reverse(text),1," ") in ("rac","llab","thcay") then found2=1; if found=1 and found1=1 then output;run;');
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Don't get into the mindset that macro is something special and should be used for everything. &amp;nbsp;It is an&amp;nbsp;&lt;STRONG&gt;additional&lt;/STRONG&gt; tool, and does nothing in of itself, only generates strings. &amp;nbsp;Almost all the time I see macro code, it is messy, obfuscated and unnecessary. &amp;nbsp;A good grasp of Base SAS is far more important as almost everything can be done there, either by processing or by data modelling.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 13:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323603#M71752</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-10T13:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323608#M71754</link>
      <description>&lt;P&gt;Apologies RW9 - i see what you are doing there and it is genius.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wondered why the first value was not included, but i need to add in a case insensitive clause to your query which will solve that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;just to throw a spanner in the works (i should have been more precise earlier), how do we work around this when out second keyword ( car yacht ball)&lt;/P&gt;&lt;P&gt;is not the last word, as i notice the query looks at last values for this second keyword, such as if we adjsuted the initial dataset to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Colour_text;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; text &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$CHAR38.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;i want a BLUE BALL please&lt;/P&gt;&lt;P&gt;did you see a blue car go by&lt;/P&gt;&lt;P&gt;i have owned a yellow yacht before&lt;/P&gt;&lt;P&gt;id never buy a red ball&lt;/P&gt;&lt;P&gt;we want a turqoise car&lt;/P&gt;&lt;P&gt;she said it was a yellow plane toy&lt;/P&gt;&lt;P&gt;he drove in his green Porsche&lt;/P&gt;&lt;P&gt;i didnt like his black heart&lt;/P&gt;&lt;P&gt;he had a grey ball&lt;/P&gt;&lt;P&gt;i saw a white plane&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;I also appreciate the note on the macro relevance, and the importance of using the alternative method, as i also presume my actual list of variables would be close to exceeding those character limits, which makes your approach all the more attractive&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;thanks once again&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 13:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323608#M71754</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T13:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323616#M71756</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the second version of the code ( starting with proc transpose ) did not identify just those results with car / yacht etc , it brought back everything with found = .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first version did however, i have just got back with an alternative scenario also to refrain from using "last" as the second keyword may not be the last word.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 13:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323616#M71756</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T13:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323620#M71760</link>
      <description>&lt;P&gt;Hi MR_E.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's actually a bit simpler for your case, here's the code modified to keep rows which will match the parse.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;* load colours names into list;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set colours;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;call symput('NAMES',catx('|',symget('NAMES'),upcase(NAME)));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%put NAMES=&amp;amp;NAMES;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;* keep matches;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data want;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set Colour_text;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if prxmatch("/[a-z]*(&amp;amp;NAMES;)([a-z]| car| ball| yacht)/i",text);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Hope it helps.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 14:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323620#M71760</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-10T14:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323623#M71762</link>
      <description>&lt;P&gt;Well, the simplest way, as you have two sets of values - again, there are various different ways - can be found below.&lt;/P&gt;
&lt;P&gt;Edit, included a plain Base SAS example further below which shows data modelling change, merging and arrays to achieve the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data colour_text;
  input text $char38.;
datalines;
i want a BLUE BALL please
did you see a blue car go by
i have owned a yellow yacht before
id never buy a red ball
we want a turqoise car
she said it was a yellow plane toy
he drove in his green Porsche
i didnt like his black heart
he had a grey ball
i saw a white plane
;
run;

data colours;
  input name $char10.;
datalines;
BLUE
YELLOW
GREEN
RED
BLACK
WHITE
;
run;

data types;
  input type $char15.;
datalines;
CAR
BALL
YACHT
;
run;

data _null_;
  set colours end=last;
  if _n_=1 then call execute('data want; set colour_text;');
  call execute(cats('if found &amp;lt; 1 then found=index(upcase(text),"',name,'");'));
  if last then call execute('run;');
run;

data _null_;
  set types end=last;
  if _n_=1 then call execute('data want; set want;');
  call execute(cats('if found2 &amp;lt; 1 then found2=index(upcase(text),"',type,'");'));
  if last then call execute('run;');
run;

data want (drop=found found2);
  set want (where=(found &amp;gt; 0 and found2 &amp;gt; 0));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* Note same test data as above */
data types;
  input type $char15.;
datalines;
CAR
BALL
YACHT
;
run;

proc transpose data=colours out=t_colors prefix=c;
  var name;
run;
proc transpose data=types out=t_types prefix=t;
  var type;
run;
data total;
  merge t_colors t_types;
run;

proc sql;
  create table WANT as
  select  A.*,
          B.*
  from    COLOUR_TEXT A
  left join TOTAL B
  on      1=1;
quit;

data want (keep=text);
  set want;
  array c c:;
  array t t:;
  do i=1 to dim(c);
    if findw(upcase(text),strip(c{i})) then found=sum(found,1);
  end;
  do i=1 to dim(t);
    if findw(upcase(text),strip(t{i})) then found2=sum(found2,1);
  end;
  if found &amp;gt; 0 and found2 &amp;gt; 0 then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jan 2017 14:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323623#M71762</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-10T14:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323636#M71763</link>
      <description>&lt;P&gt;If you mathcing logic is more complex then you probably want to change from using a simple FIND() function call to using more complex test such as the REGEX. &amp;nbsp;You can build the REGEX from VARIABLES instead of MACRO VARIABLES. &amp;nbsp;Although if your datasets are large you might want to looking into ways to get each distinct generated REGEX expression parsed only once for the data step rather than re-compiling them for every observation of that data you are checking.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 14:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323636#M71763</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-01-10T14:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323643#M71764</link>
      <description>&lt;P&gt;wow - i removed the smiley face &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; and it produced the exact results i wanted - thankyou&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however, and whilst i hate to caveat this, i feared this all along, there is a limit on the characters in this approach and it becomes unstable , whilst it still provided the correct results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;SYMBOLGEN: Macro variable NAMES resolves to BLUE YELLOW GREEN RED BLACK WHITE BLUE YELLOW GREEN RED BLACK WHITE BLUE YELLOW GREEN&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;RED BLACK WHITE BLUE YELLOW GREEN RED BLACK&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;WHITE|BLUE|YELLOW|GREEN|RED|BLACK|WHITE|BLUE|YELLOW|GREEN|RED|BLACK|WHITE|BLUE|YELLOW|GREEN|RED|BLACK|WHITE|BLUE|YELLOW|&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;GREEN|RED|BLACK|WHITE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;WARNING: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;marks.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;This concerns me as my actual list is at least 4000 variables long and will likely grow going forwards, which makes the above issue even more worrying.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Whilst PRXMATCH as you have done is my preffered method, i think the Call reference routine may not be viable this time (please tell me im wrong).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thank you regardless of the outcome&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 14:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323643#M71764</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T14:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323646#M71765</link>
      <description>&lt;P&gt;To make this handle large cases remove the macro variable and add DO loops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this. &amp;nbsp;Read more about how to use REGEX functions in SAS and you could possible optimize it more.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array regex (4000) $200 _temporary_ ;
* load colours names into list;
  if _n_=1 then do p=1 to nobs ;
     set colours point=p nobs=nobs;
     * Build REGEX for this "NAME" ;
     regex(p)=cats("/[a-z]*(",NAME,")([a-z]| car| ball| yacht)/i");
  end;
* keep matches;
   set Colour_text;
   found=0;
   do i=1 to nobs until(found);
      found=prxmatch(regex(i),text);
   end;
   if found;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jan 2017 14:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323646#M71765</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-01-10T14:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323652#M71766</link>
      <description>&lt;P&gt;Wow - that is impressive, as i have just mentioned to DanielSantos both approaches work great except for the char limit on the other solution, hence why i believe yours may be the answer ( no sight of macros anywhere &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;before i accept the solution , i wonder of there is limitations to the extent of my query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e if we change the second keyword to later on in the text it would be an invalid answer, for example the below.&lt;/P&gt;&lt;P&gt;I am looking for a yellow Yacht, but if the yacht keyword was later on in the code we would still pick this up as found2 &amp;gt; found1 still, but if my desire was specifically Yellow Yacht, this would infact be an invalid result. ( i realise you have answered the solution im just wondering how far my query could go with horrid data)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; colour_text;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; text &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$char50.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;i want a BLUE BALL please&lt;/P&gt;&lt;P&gt;did you see a blue car go by&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000"&gt;i have owned a yellow SHIP but not a yacht before&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;id never buy a red ball&lt;/P&gt;&lt;P&gt;we want a turqoise car&lt;/P&gt;&lt;P&gt;she said it was a yellow plane toy&lt;/P&gt;&lt;P&gt;he drove in his green Porsche&lt;/P&gt;&lt;P&gt;i didnt like his black heart&lt;/P&gt;&lt;P&gt;he had a grey ball&lt;/P&gt;&lt;P&gt;i saw a white plane&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;to put this in context -&amp;nbsp;The issue is: The real data is actually seperating actual cities from streets ,ie i want Paris when its a city in the text, and another dataset to identify when its a street&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;21 rouge street Paris - correct result for city dataset&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;21 rouge street Paris invoice to 15 kruger street - would go street dataset as street&amp;gt;cityname (found2&amp;gt;found1)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;now, one answer would be to seperate the data after one of the cities is found ,i.e city found move additional string into next field or ignore, but that would miss the street string etc (yacht car ball)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;In summary , is it possible to identify only those variables where the street is immediately after the city name (or in our instance the type is right after the colour) only. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I imagine this would involve a calculation like the index value of found2 (26)&amp;nbsp;is &amp;lt;= 6 of end of found1 (19)&amp;nbsp;i.e&amp;nbsp;Paris (s is 19) Street (t is 26)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;given the number of possibilities this was why i was inclined to go with reg expressions, but as i have learnt your query is more viable.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Am i asking too much?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Hopefully i have not lost you with that, and i appreciate the assistance regardless, sensational solutions&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 15:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323652#M71766</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T15:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323696#M71781</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;pointed out, the correct approach to circumvent the problem would be to remove the direct references to the macro var and replace them with the symget function (the former is resolved at compile time, the latest at runtime).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will suffice:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data want;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;set Colour_text;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if prxmatch("/[a-z]*("!!strip(symget('NAMES'))!!";)( car| ball| yacht)/i",text);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;This will solve the problem of the yellow yacht/(not yellow) yacht and you'll be good with a prxmatch expression up&amp;nbsp;to 32K in length... But, I would not use this kind of approach with a lot of data as it's probably not the best performance wise (regular expresions are quite CPU intensive)... Give it a try to see if it works well for you.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;More on symget:&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000202938.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000202938.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Hope it helps.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 16:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323696#M71781</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-01-10T16:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323707#M71786</link>
      <description>&lt;P&gt;Yes, thats a bit more in depth. &amp;nbsp;I would start with do some data cleaning on the data you have. &amp;nbsp;Identify all the rules you need to apply. &amp;nbsp;Split the string up into street/city parts. &amp;nbsp;Why for instance does city before street matter? &amp;nbsp;Its quite hard to try to visualise from whats provided. &amp;nbsp;Likelihood is regex or text miner would be better at parsing string data. &amp;nbsp;Set out all your data cleaning activities, implement them into a nicely structured dataset, then start processing that data. &amp;nbsp;At the moment we are just going round in cricles.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 16:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323707#M71786</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-10T16:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323717#M71789</link>
      <description>Not at all, you've greatly helped me understand a different approach to this.&lt;BR /&gt;&lt;BR /&gt;I never expected a simple solution but alternative pov's are a great help&lt;BR /&gt;&lt;BR /&gt;Much appreciated&lt;BR /&gt;</description>
      <pubDate>Tue, 10 Jan 2017 17:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323717#M71789</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-10T17:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Storing a list of values (from a dataset) in a macro variable to use in a regular expression sea</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323911#M71851</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13832"&gt;@DanielSantos&lt;/a&gt;&amp;nbsp;thankyou both for this solution, this has helped me modify my exact query to exactly how i wanted, being able to also include a second array fairly easily which was also require (additional requirements)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all for your assistance, its great to see Fantastic minds at work&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 13:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Storing-a-list-of-values-from-a-dataset-in-a-macro-variable-to/m-p/323911#M71851</guid>
      <dc:creator>MR_E</dc:creator>
      <dc:date>2017-01-11T13:09:47Z</dc:date>
    </item>
  </channel>
</rss>

