<?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: replace values in list of variables using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571867#M161343</link>
    <description>&lt;P&gt;No macro needed. Use an ARRAY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set dat;
    array v var01-var12;
    do i=1 to dim(v);
        if v(i)='C' then v(i)='2';
     end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 08 Jul 2019 17:18:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-07-08T17:18:00Z</dc:date>
    <item>
      <title>replace values in list of variables using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571866#M161342</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to replace values of a list of similar variables (replace 'C' with '2') for 12 variables:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set dat;
  if var01 = 'C' then var01 = '2';
  if var02 = 'C' then var02 = '2';
  if var03 = 'C' then var03 = '2';
  ...
  if var12 = 'C' then var12 = '2';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I simplify this code with macro/loop? I tried the following codes but did not work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var_list = var01-var12;
%macro loop(var_list);
%local i next_var;
data want;
   set dat;
   %do i = 1 %to %sysfunc(countw(&amp;amp;var_list));
   %let next_name = %scan(&amp;amp;var_list, &amp;amp;i);
   if &amp;amp;next_var = 'C' then &amp;amp;next_var = '2';
   %end;
run;
%mend;
%loop(&amp;amp;var_list); &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any idea? Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 17:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571866#M161342</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2019-07-08T17:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: replace values in list of variables using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571867#M161343</link>
      <description>&lt;P&gt;No macro needed. Use an ARRAY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set dat;
    array v var01-var12;
    do i=1 to dim(v);
        if v(i)='C' then v(i)='2';
     end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jul 2019 17:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571867#M161343</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-08T17:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: replace values in list of variables using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571868#M161344</link>
      <description>How complicated does this get? Would a format be appropriate as well - do you need actual recoding to numeric values as well? Or will a character variable be sufficient?</description>
      <pubDate>Mon, 08 Jul 2019 17:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571868#M161344</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-08T17:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: replace values in list of variables using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571870#M161346</link>
      <description>a character variable is sufficient.</description>
      <pubDate>Mon, 08 Jul 2019 17:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571870#M161346</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2019-07-08T17:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: replace values in list of variables using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571871#M161347</link>
      <description>Thanks it worked!</description>
      <pubDate>Mon, 08 Jul 2019 17:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-in-list-of-variables-using-macro/m-p/571871#M161347</guid>
      <dc:creator>panda</dc:creator>
      <dc:date>2019-07-08T17:28:12Z</dc:date>
    </item>
  </channel>
</rss>

