<?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 Pass string values into Macro call in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pass-string-values-into-Macro-call/m-p/502043#M133962</link>
    <description>&lt;P&gt;Here is the code. It doesn't seem to be removing (replacing with blank) the strings that I am providing as the last parameter in the macro call. Anyone have any ideas. I've tried slight variations but with no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro word_removal(tbl_in, tbl_out, first_field, second_field, str_list);
   data &amp;amp;tbl_out;
    set &amp;amp;tbl_in;
      %do i = 1 %to %sysfunc(countw(&amp;amp;str_list.));
        %let current_str = %scan(&amp;amp;str_list., &amp;amp;i.);
		&amp;amp;second_field = tranwrd(&amp;amp;first_field, "&amp;amp;current_str.", '');
      %end;
   run;    
%mend word_removal;

%word_removal(input_table, output_table, field_one, field_two, ('hello','world','beta','alpha'));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 20:34:30 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2018-10-05T20:34:30Z</dc:date>
    <item>
      <title>Pass string values into Macro call</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-string-values-into-Macro-call/m-p/502043#M133962</link>
      <description>&lt;P&gt;Here is the code. It doesn't seem to be removing (replacing with blank) the strings that I am providing as the last parameter in the macro call. Anyone have any ideas. I've tried slight variations but with no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro word_removal(tbl_in, tbl_out, first_field, second_field, str_list);
   data &amp;amp;tbl_out;
    set &amp;amp;tbl_in;
      %do i = 1 %to %sysfunc(countw(&amp;amp;str_list.));
        %let current_str = %scan(&amp;amp;str_list., &amp;amp;i.);
		&amp;amp;second_field = tranwrd(&amp;amp;first_field, "&amp;amp;current_str.", '');
      %end;
   run;    
%mend word_removal;

%word_removal(input_table, output_table, field_one, field_two, ('hello','world','beta','alpha'));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 20:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-string-values-into-Macro-call/m-p/502043#M133962</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2018-10-05T20:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Pass string values into Macro call</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pass-string-values-into-Macro-call/m-p/502046#M133963</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73936"&gt;@JediApprentice&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here is the code. It doesn't seem to be removing (replacing with blank) the strings that I am providing as the last parameter in the macro call. Anyone have any ideas. I've tried slight variations but with no luck.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro word_removal(tbl_in, tbl_out, first_field, second_field, str_list);
   data &amp;amp;tbl_out;
    set &amp;amp;tbl_in;
      %do i = 1 %to %sysfunc(countw(&amp;amp;str_list.));
        %let current_str = %scan(&amp;amp;str_list., &amp;amp;i.);
		&amp;amp;second_field = tranwrd(&amp;amp;first_field, "&amp;amp;current_str.", '');
      %end;
   run;    
%mend word_removal;

%word_removal(input_table, output_table, field_one, field_two, ('hello','world','beta','alpha'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have two issues likely. First is the macro call is introducing problems with the way that you pass the list. Remove the (), the ' and commas.&lt;/P&gt;
&lt;P&gt;Second if you want to remove ALL of the words then your logic is incorrect. You keep replacing the string from the original value. If you pass more than one word then you are currently only actually replacing the last one in the list.&lt;/P&gt;
&lt;PRE&gt;%macro word_removal(tbl_in, tbl_out, first_field, second_field, str_list);
   data &amp;amp;tbl_out;
    set &amp;amp;tbl_in;
      %do i = 1 %to %sysfunc(countw(&amp;amp;str_list.));
        %let current_str = %scan(&amp;amp;str_list., &amp;amp;i.);
         %if &amp;amp;i=1 %then %do;
      		&amp;amp;second_field = tranwrd(&amp;amp;first_field, "&amp;amp;current_str.", '');
          %end;
          %else %do;
      		&amp;amp;second_field = tranwrd(&amp;amp;second_field, "&amp;amp;current_str.", '');
          %end;
     %end;
   run;    
%mend word_removal;

%word_removal(Sashelp.cars,work.junk, make, newmake,Acura Audi);



&lt;/PRE&gt;
&lt;P&gt;Quotes and commas in a macro parameter are very often either not needed with careful planning and often a cause of problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 21:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pass-string-values-into-Macro-call/m-p/502046#M133963</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-05T21:00:56Z</dc:date>
    </item>
  </channel>
</rss>

