<?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: Array syntax issue when converting a data step into macro statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968984#M376702</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;thanks for correct the syntax! Change the single quotation mark in &lt;EM&gt;prxmatch('//');&lt;/EM&gt; was the only thing that I did not try (I even tried something like &lt;EM&gt;prxmatch('/("&amp;amp;list")/')&lt;/EM&gt; because I was not familar with &lt;EM&gt;perl&lt;/EM&gt; &lt;EM&gt;(prxmatch)&lt;/EM&gt; syntax and mistakenly believe that the single quotation mark was a fixed syntax in &lt;EM&gt;prxmatch()&lt;/EM&gt; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now the most efficient and succinct answer (no array, no macro needed) for the question is as follows, and hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;, what do you think&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data street_name;
   input st_nm $ typ 4.;
   datalines;
ROAD 1
RD 1
STREET 1
ST 1
PLACE 1
PL 1
PO_BOX 3
UNIT 2
SUITE 2
;
run;
data address;
   input address $20.;
   datalines;
3 ARRON ROAD
15 BONNY RD
7 DAISY STREET
PO BOX 15
UNIT 6
89 ROSE PLACE
9 HOPE ST
;
run;
proc sql noprint;
select st_nm
   into :strlist separated by '|'
   from street_name
   where typ=1;
quit;
data str_address;
   set address;
   loc=prxmatch("/(&amp;amp;strlist)/",address);
   if loc^=0 then found=1;
run;
proc print data=str_address;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1749823242077.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107809iA1448DF9FC19B9DB/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1749823242077.png" alt="dxiao2017_0-1749823242077.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jun 2025 14:08:47 GMT</pubDate>
    <dc:creator>dxiao2017</dc:creator>
    <dc:date>2025-06-13T14:08:47Z</dc:date>
    <item>
      <title>Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/967902#M376464</link>
      <description>&lt;P&gt;Dear all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am doing some address data cleaning for my company. I managed to get the job done but I am still not satisfied as I know the script can be even simpler. Below is what I have achieved. I used values in street_name table to search in the address column in dataset (address). If there is a match the script will give me a value 1. BTW, the script is copied from our forum. The script works perfectly fine. But my curiosity pushes to go one step further - adding it in a macro statement. So when I run %addr_clean(macro_nm, 1)&amp;nbsp; it will give me the same result. However, I am stuck at converting array syntax to a macro-understanding format. Please help me out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;DATA STREET_NAME;&lt;/DIV&gt;&lt;DIV&gt;INPUT ST_NM $ TYP 4.;&lt;/DIV&gt;&lt;DIV&gt;DATALINES;&lt;/DIV&gt;&lt;DIV&gt;ROAD 1&lt;/DIV&gt;&lt;DIV&gt;RD 1&lt;/DIV&gt;&lt;DIV&gt;STREET 1&lt;/DIV&gt;&lt;DIV&gt;ST 1&lt;/DIV&gt;&lt;DIV&gt;PLACE 1&lt;/DIV&gt;&lt;DIV&gt;PL 1&lt;/DIV&gt;&lt;DIV&gt;PO_BOX 3&lt;/DIV&gt;&lt;DIV&gt;UNIT 2&lt;/DIV&gt;&lt;DIV&gt;SUITE 2&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;DATA ADDRESS;&lt;/DIV&gt;&lt;DIV&gt;INPUT ADDRESS $20.;&lt;/DIV&gt;&lt;DIV&gt;DATALINES;&lt;/DIV&gt;&lt;DIV&gt;3 ARRON ROAD&lt;/DIV&gt;&lt;DIV&gt;15 BONNY RD&lt;/DIV&gt;&lt;DIV&gt;7 DAISY STREET&lt;/DIV&gt;&lt;DIV&gt;PO BOX 15&lt;/DIV&gt;&lt;DIV&gt;UNIT 6&lt;/DIV&gt;&lt;DIV&gt;89 ROSE PLACE&lt;/DIV&gt;&lt;DIV&gt;9 HOPE ST&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PROC SQL NOPRINT;&lt;/DIV&gt;&lt;DIV&gt;SELECT "'" || " "|| STRIP(ST_NM) || "'" INTO: STREET SEPARATED BY ', ' FROM STREET_NAME WHERE TYP = 1.;&lt;/DIV&gt;&lt;DIV&gt;QUIT;&lt;/DIV&gt;&lt;DIV&gt;%PUT &amp;amp;STREET.;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;DATA STREET_ADDRESS;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;SET ADDRESS;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;ARRAY NN (%sysfunc(countw(QUOTE(&amp;amp;STREET.), %STR(,)))) $ 10 _TEMPORARY_ (&amp;amp;STREET.);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;DO I=1 TO DIM(NN);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF FIND(ADDRESS,STRIP(NN[i]),'i') GT 0 THEN DO;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FOUND=1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MATCH=NN[i];&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LEAVE;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; END;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;END;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;DROP I;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;=========================================================&lt;/DIV&gt;&lt;DIV&gt;%MACRO ADDR_CLEAN(ST_MACRO, TYP);&lt;/DIV&gt;&lt;DIV&gt;PROC SQL NOPRINT;&lt;/DIV&gt;&lt;DIV&gt;SELECT "'" || " "|| STRIP(ST_NM) || "'" INTO: &amp;amp;ST_MACRO. SEPARATED BY ', ' FROM STREET_NAME WHERE TYP =&amp;amp;TYP..;&lt;/DIV&gt;&lt;DIV&gt;QUIT;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;/*I am stuck here and not able to do the rest to fit the code in a macro statement*/;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;%MEND;&lt;/DIV&gt;&lt;DIV&gt;%ADDR_CLEAN(ST, TYP);&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jun 2025 08:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/967902#M376464</guid>
      <dc:creator>SunnySong</dc:creator>
      <dc:date>2025-06-02T08:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/967906#M376465</link>
      <description>&lt;P&gt;Macro is a text processor. To find the strings using macro logic, you need to remove the quotes. Here is some code to get you started.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO ADDR_CLEAN(ST_MACRO, TYP);
PROC SQL NOPRINT;
SELECT STRIP(ST_NM) INTO: &amp;amp;ST_MACRO. SEPARATED BY ',' FROM STREET_NAME 
 WHERE TYP =&amp;amp;TYP;
QUIT;
/*I am stuck here and not able to do the rest to fit the code in a macro statement*/;
%put &amp;amp;st;
%let count=&amp;amp;sqlobs;
%put &amp;amp;count;

data street_address;
set address;
%do i=1 %to &amp;amp;count;
 %let x=%scan(%bquote(&amp;amp;st),&amp;amp;i,%str(,));
 if find(address,"&amp;amp;x",'i') gt 0 then found=1;
%end;
run;

proc print data=street_address;
run;

%MEND;
%ADDR_CLEAN(ST, 1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Jun 2025 11:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/967906#M376465</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-06-02T11:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/967908#M376467</link>
      <description>&lt;P&gt;Before you try to use macro logic to generate a SAS program make sure you know what SAS program you want to generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks to me like you are trying to generate one of these three statements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array nn [6] _temporary_ ('ROAD' 'RD' 'STREET' 'ST' 'PLACE' 'PL');
array nn [1] _temporary_ ('PO_BOX');
array nn [2] _temporary_ ('UNIT' 'SUITE');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The part that varies is the count and the space delimited list of quoted words.&lt;/P&gt;
&lt;P&gt;So modify your SQL query so that it generates those two values into macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select quote(trim(st_nm),"'") into :streetlist separated by ' '
  from street_name
  where typ = &amp;amp;typ
;
%let nstreet=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use NSTREET and STREETLIST macro variables to generate the array statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array nn [&amp;amp;nstreet] _temporary_ (&amp;amp;streetlist);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Things to note.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;PROC SQL already counts the number of observations returned by a query.&amp;nbsp; So use that instead of trying to re-count them later.&lt;/LI&gt;
&lt;LI&gt;Use the QUOTE() function to add quotes around values. It will properly double up any embedded quotes.&lt;/LI&gt;
&lt;LI&gt;Use single quotes when generating quoted strings so that any &amp;amp; or % characters in the values are not interpreted by the macro processor.&lt;/LI&gt;
&lt;LI&gt;The list of initial values for an array does not need to use commas as the delimiter, spaces work just the same.&amp;nbsp; And since macro variables with commas in them cause trouble when passed to macro calls or macro function calls it is better to just use spaces.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that you should not use STRIP() when generating quoted values from character variables.&amp;nbsp; The resulting quoted string will not have the leading spaces and so will not accurately reflect the value that was in the original character variable.&amp;nbsp; Instead use TRIM() to remove only the&amp;nbsp; trailing spaces.&amp;nbsp; Not having trailing spaces in the quoted value will not cause an issue in comparison since SAS ignores trailing spaces when comparing strings.&amp;nbsp; &amp;nbsp;Perhaps not actually wanted in this case since your probably actually do want to remove any leading spaces that might have gotten into the TYP variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that if you call the macro like you did:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%ADDR_CLEAN(ST, TYP);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with the second argument set to the string TYP then all of the street types will be included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is because the resulting where clause of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where typ = typ&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will be true for every observation of the STREET_NAME dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jun 2025 15:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/967908#M376467</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-02T15:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968333#M376529</link>
      <description>&lt;P&gt;Hi, Kathryn,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your in-need support. I was quite busy with an urgent project and didn't have a chance to confirm your solution. Yeah, your code is a lot simpler than mine and it works perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Quoting and unquoting sometime are really confusing, thanks for valuable advice. I am truly grateful. Your help definitely saved me a lot of time reasearching.&amp;nbsp;You know this is my first post in SAS community and I feel like I am welcomed by our prompt reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will talk to you again when next question comes. LOL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sunny&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 14:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968333#M376529</guid>
      <dc:creator>SunnySong</dc:creator>
      <dc:date>2025-06-06T14:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968335#M376530</link>
      <description>&lt;P&gt;Hi, Tom,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply. It is such an elegant piece of code and so easy to understand. With your help, I have had a better understanding of Array. I am a newbie to Array field. But with your demostration, I feel like I am also able to handle this method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;As I said earlier, this is my first post and thank you so much to help me out. I am so thankful.&amp;nbsp;I wish I could learn and grow in this community with great support from those smart people like you and Kathyn.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again, thank your for lending me a helping hend when I needed the most.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep in touch.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sunny Song&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 14:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968335#M376530</guid>
      <dc:creator>SunnySong</dc:creator>
      <dc:date>2025-06-06T14:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968336#M376531</link>
      <description>How come I can only take one post as a solution? You have truly helped me as well.</description>
      <pubDate>Fri, 06 Jun 2025 14:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968336#M376531</guid>
      <dc:creator>SunnySong</dc:creator>
      <dc:date>2025-06-06T14:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968337#M376532</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How come I can only take one post as a solution? You have truly helped me as well.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is how the software tool SAS is using to run the forum works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it does not matter, the main thing is to make sure and select an answer so future users that are searching for the same type of question will know the thread has an answer and so might be useful for them.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 14:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968337#M376532</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-06T14:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968343#M376533</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How come I can only take one post as a solution? You have truly helped me as well.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm going to give Tom's post an extra like to compensate for it not being the accepted solution. :&lt;FONT face="arial,helvetica,sans-serif"&gt;-&lt;/FONT&gt;)&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 15:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968343#M376533</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-06-06T15:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968854#M376652</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;, would &lt;EM&gt;prxmatch&lt;/EM&gt; make the answer easier? The code and results are as follows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the &lt;EM&gt;loc1=;&lt;/EM&gt; statement does not work because it seems that the &lt;EM&gt;&amp;amp;strlist&lt;/EM&gt;&amp;nbsp; macro was not resolved. The &lt;EM&gt;loc=;&lt;/EM&gt; statement worked because I copied the value of the &lt;EM&gt;&amp;amp;strlist&lt;/EM&gt; into the statement manually. My furthur question is: how to make the &lt;EM&gt;loc1=prxmatch('/(&amp;amp;strlist)/',address);&lt;/EM&gt; work, i.e., resolve the &lt;EM&gt;&amp;amp;strlist&lt;/EM&gt; macro properly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data street_name;
   input st_nm $ typ 4.;
   datalines;
ROAD 1
RD 1
STREET 1
ST 1
PLACE 1
PL 1
PO_BOX 3
UNIT 2
SUITE 2
;
run;
data address;
   input address $20.;
   datalines;
3 ARRON ROAD
15 BONNY RD
7 DAISY STREET
PO BOX 15
UNIT 6
89 ROSE PLACE
9 HOPE ST
;
run;
proc sql noprint;
select st_nm
   into :strlist separated by '|'
   from street_name
   where typ=1;
quit;
%put &amp;amp;strlist;
/*ROAD|RD|STREET|ST|PLACE|PL*/
data str_address;
   set address;
   loc=prxmatch('/(ROAD|RD|STREET|ST|PLACE|PL)/',address);
   if loc^=0 then found=1;
   loc1=prxmatch('/(&amp;amp;strlist)/',address);
run;
proc print data=str_address;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_1-1749737614031.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107773i98D2BBD0798335FA/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_1-1749737614031.png" alt="dxiao2017_1-1749737614031.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jun 2025 14:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968854#M376652</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-06-12T14:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968857#M376654</link>
      <description>&lt;P&gt;In general new questions should be raised on a new thread.&amp;nbsp; You can always include a link back to the old question for context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the macro processors ignore strings bounded on the outside by single quotes.&amp;nbsp; Use double quotes if you want the macro processor to process the content.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;loc1=prxmatch("/(&amp;amp;strlist)/",address);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jun 2025 14:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968857#M376654</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-12T14:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968984#M376702</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;thanks for correct the syntax! Change the single quotation mark in &lt;EM&gt;prxmatch('//');&lt;/EM&gt; was the only thing that I did not try (I even tried something like &lt;EM&gt;prxmatch('/("&amp;amp;list")/')&lt;/EM&gt; because I was not familar with &lt;EM&gt;perl&lt;/EM&gt; &lt;EM&gt;(prxmatch)&lt;/EM&gt; syntax and mistakenly believe that the single quotation mark was a fixed syntax in &lt;EM&gt;prxmatch()&lt;/EM&gt; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now the most efficient and succinct answer (no array, no macro needed) for the question is as follows, and hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;, what do you think&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data street_name;
   input st_nm $ typ 4.;
   datalines;
ROAD 1
RD 1
STREET 1
ST 1
PLACE 1
PL 1
PO_BOX 3
UNIT 2
SUITE 2
;
run;
data address;
   input address $20.;
   datalines;
3 ARRON ROAD
15 BONNY RD
7 DAISY STREET
PO BOX 15
UNIT 6
89 ROSE PLACE
9 HOPE ST
;
run;
proc sql noprint;
select st_nm
   into :strlist separated by '|'
   from street_name
   where typ=1;
quit;
data str_address;
   set address;
   loc=prxmatch("/(&amp;amp;strlist)/",address);
   if loc^=0 then found=1;
run;
proc print data=str_address;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1749823242077.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107809iA1448DF9FC19B9DB/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1749823242077.png" alt="dxiao2017_0-1749823242077.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jun 2025 14:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/968984#M376702</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-06-13T14:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969347#M376836</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;SPAN&gt;dxiao2017,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for sharing this easy looking but quite advanced code. I do know&amp;nbsp;&lt;EM&gt;prxmatch&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;can simplify these searching multiple key words from a long list of strings. I myself even downloaded a tutorial book to learn. But it is not that easy. I only learned some basic knowledge.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regarding how to get loc1 values, it is in the sql statement.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql noprint;
select st_nm
   into :strlist separated by '|'
   from street_name
   where typ=&lt;STRONG&gt;2&lt;/STRONG&gt;;
quit;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Then we can wrap your whole code up with a macro statement %macro street_clean (type). Giving the type value 1, 2, 3, will assign different list of streets. Also Loc0 or Loc1 needs to be changed to Loc&amp;amp;type. to ensure the data results won't be overwritten.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will test it when I go home and update you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again, thanks for your sharing. Very inspiring.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sunny Song&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2025 02:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969347#M376836</guid>
      <dc:creator>SunnySong</dc:creator>
      <dc:date>2025-06-19T02:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969373#M376839</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;, thank you for the feedback! I am glad that I can contribute and help a bit&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt; and best luck in testing your code (the macro you are going to write)!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2025 12:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969373#M376839</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-06-19T12:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969389#M376841</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;, I think this is the macro you are going to write. "PO_BOX" in the first dataset became "PO BOX" in the second dataset, so the value of the new column in the final output table is missing (it would be "3" if the "PO_BOX" value was the same in the first and second dataset). If you want to deal with this issue (the value in the second dataset is different from those in the first dataset) you need more coding step. You do not need any parameters for the macro. The macro can be simplified a bit because what you want is just the last output table. When finalize the macro do not forget to add the %local statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data street_name;
   input st_nm $ typ 4.;
   datalines;
ROAD 1
RD 1
STREET 1
ST 1
PLACE 1
PL 1
PO_BOX 3
UNIT 2
SUITE 2
;
run;
proc print data=street_name;run;
data address;
   input address $20.;
   datalines;
3 ARRON ROAD
15 BONNY RD
7 DAISY STREET
PO BOX 15
UNIT 6
89 ROSE PLACE
9 HOPE ST
;
run;
proc print data=address;run;
%macro addressloc;
proc sql;
select distinct typ
   into :typlist
   from street_name;
quit;
%put &amp;amp;typlist &amp;amp;sqlobs;
%let n=&amp;amp;sqlobs;
%put &amp;amp;n;
%do i=1 %to &amp;amp;n;
proc sql;
select st_nm
   into :strlist separated by '|'
   from street_name
   where typ=&amp;amp;i;
quit;
%put &amp;amp;strlist;
data str_address;
   set address;
   set str_address;
   loc=prxmatch("/(&amp;amp;strlist)/",address);
   if loc^=0 then found=&amp;amp;i;
run;
proc print data=str_address;run;
%end;
%mend addressloc;
%addressloc;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1750344114932.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107907iDB1B7B2EE21650A8/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1750344114932.png" alt="dxiao2017_0-1750344114932.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_1-1750344179778.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107908i5709A1D4EC443E8D/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_1-1750344179778.png" alt="dxiao2017_1-1750344179778.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_2-1750344249553.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107909iEF72F34F0DD745B9/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_2-1750344249553.png" alt="dxiao2017_2-1750344249553.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_3-1750344308982.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107910i288893679546697D/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_3-1750344308982.png" alt="dxiao2017_3-1750344308982.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jun 2025 14:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969389#M376841</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-06-19T14:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Array syntax issue when converting a data step into macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969441#M376849</link>
      <description>&lt;P&gt;Sorry I made several mistakes in the code in my last thread&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt;and corrected them here. The code should be like this. But I still have not wrote the step for combine the three&amp;nbsp; str_address&amp;amp;i datasets together&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt;, hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/475590"&gt;@SunnySong&lt;/a&gt;&amp;nbsp;, have you finished writing your macro, please kindly let me know, thanks&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data street_name;
   input st_nm $ typ 4.;
   datalines;
ROAD 1
RD 1
STREET 1
ST 1
PLACE 1
PL 1
PO_BOX 3
UNIT 2
SUITE 2
;
run;
proc print data=street_name;run;
data address;
   input address $20.;
   datalines;
3 ARRON ROAD
15 BONNY RD
7 DAISY STREET
PO BOX 15
UNIT 6
89 ROSE PLACE
9 HOPE ST
;
run;
proc print data=address;run;
%macro addressloc;
proc sql;
select distinct typ
   into :typlist1-
   from street_name;
quit;
%put &amp;amp;typlist1 &amp;amp;sqlobs;
%let n=&amp;amp;sqlobs;
%put &amp;amp;n;
%do i=1 %to &amp;amp;n;
proc sql;
select st_nm
   into :strlist separated by '|'
   from street_name
   where typ=&amp;amp;&amp;amp;typlist&amp;amp;i;
quit;
%put &amp;amp;strlist;
data str_address&amp;amp;i;
   set address;
   loc=prxmatch("/(&amp;amp;strlist)/",address);
   if loc^=0 then found=&amp;amp;&amp;amp;typlist&amp;amp;i;
run;
proc print data=str_address&amp;amp;i;run;
%end;
%mend addressloc;
%addressloc;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; ROAD|RD|STREET|ST|PLACE|PL
 NOTE: There were 7 observations read from the data set WORK.ADDRESS.
 NOTE: The data set WORK.STR_ADDRESS1 has 7 observations and 3 variables.

 UNIT|SUITE
 NOTE: There were 7 observations read from the data set WORK.ADDRESS.
 NOTE: The data set WORK.STR_ADDRESS2 has 7 observations and 3 variables.

 PO_BOX
 NOTE: There were 7 observations read from the data set WORK.ADDRESS.
 NOTE: The data set WORK.STR_ADDRESS3 has 7 observations and 3 variables.

&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1750426277546.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107928iFC60CBC85811A862/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1750426277546.png" alt="dxiao2017_0-1750426277546.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_1-1750426351822.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107929iA6794AE0BB02E47B/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_1-1750426351822.png" alt="dxiao2017_1-1750426351822.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_2-1750426417726.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107930i4EDC730781DAAB1F/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_2-1750426417726.png" alt="dxiao2017_2-1750426417726.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_3-1750426484955.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/107931i3894F7EFFEB2F7FB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dxiao2017_3-1750426484955.png" alt="dxiao2017_3-1750426484955.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jun 2025 13:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-syntax-issue-when-converting-a-data-step-into-macro/m-p/969441#M376849</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-06-20T13:42:51Z</dc:date>
    </item>
  </channel>
</rss>

