<?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 Changing the Value of a Macro Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376121#M276570</link>
    <description>&lt;P&gt;I have tried so many different methods, and I can't find out how to change a part of a value of a macro variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My program assigns macro variables (RANGE1 through RANGEn) that contain a range that is used later in a conditional statement. &amp;nbsp;I have a couple of variables that I want to edit. &amp;nbsp;The values are:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;(upper(WEIGHT_U)="KG" and WEIGHT not between 137 and 205)&lt;/LI&gt;&lt;LI&gt;(upper(WEIGHT_U)="LB" and WEIGHT not between 137 and 205)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I need to change "WEIGHT_U" to "WEIGHTU". &amp;nbsp;Below is a snippet of what I am trying to do where &amp;amp;cnt. is the number of range statements previously defined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro vsrange;
   %do i=1 %to &amp;amp;cnt;
      %if %index(%substr(%str(&amp;amp;&amp;amp;range&amp;amp;i.),2,31),WEIGHT_U)&amp;gt;0 %then %do;&lt;BR /&gt;         %let &amp;amp;&amp;amp;range&amp;amp;i=%sysfunc(tranwrd(&amp;amp;&amp;amp;range&amp;amp;i.,WEIGHT_U,WEIGHTU));&lt;BR /&gt;      %end;&lt;BR /&gt;   %end;
%mend vsrange;
%vsrange;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am sure that there may be issues with the fact that the macro values contain quotes and parentheses. &amp;nbsp;I am trying to fix that in the %index() function. &amp;nbsp;I also can't have more than 32 characters (according to an error message), but I can't subset in the %let statement because that will alter the macro value. &amp;nbsp;It also looks like the %let statement is having a hard time assigning a value to an existing macro&amp;nbsp;variable being referenced with &amp;amp;&amp;amp;. &amp;nbsp;Can anyone see what I should possibly do to make my necessary changes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jul 2017 17:52:30 GMT</pubDate>
    <dc:creator>djbateman</dc:creator>
    <dc:date>2017-07-14T17:52:30Z</dc:date>
    <item>
      <title>Changing the Value of a Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376121#M276570</link>
      <description>&lt;P&gt;I have tried so many different methods, and I can't find out how to change a part of a value of a macro variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My program assigns macro variables (RANGE1 through RANGEn) that contain a range that is used later in a conditional statement. &amp;nbsp;I have a couple of variables that I want to edit. &amp;nbsp;The values are:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;(upper(WEIGHT_U)="KG" and WEIGHT not between 137 and 205)&lt;/LI&gt;&lt;LI&gt;(upper(WEIGHT_U)="LB" and WEIGHT not between 137 and 205)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I need to change "WEIGHT_U" to "WEIGHTU". &amp;nbsp;Below is a snippet of what I am trying to do where &amp;amp;cnt. is the number of range statements previously defined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro vsrange;
   %do i=1 %to &amp;amp;cnt;
      %if %index(%substr(%str(&amp;amp;&amp;amp;range&amp;amp;i.),2,31),WEIGHT_U)&amp;gt;0 %then %do;&lt;BR /&gt;         %let &amp;amp;&amp;amp;range&amp;amp;i=%sysfunc(tranwrd(&amp;amp;&amp;amp;range&amp;amp;i.,WEIGHT_U,WEIGHTU));&lt;BR /&gt;      %end;&lt;BR /&gt;   %end;
%mend vsrange;
%vsrange;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am sure that there may be issues with the fact that the macro values contain quotes and parentheses. &amp;nbsp;I am trying to fix that in the %index() function. &amp;nbsp;I also can't have more than 32 characters (according to an error message), but I can't subset in the %let statement because that will alter the macro value. &amp;nbsp;It also looks like the %let statement is having a hard time assigning a value to an existing macro&amp;nbsp;variable being referenced with &amp;amp;&amp;amp;. &amp;nbsp;Can anyone see what I should possibly do to make my necessary changes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 17:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376121#M276570</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2017-07-14T17:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the Value of a Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376128#M276571</link>
      <description>&lt;P&gt;Why double ampersands? From what you said, you want the macro variable names to start with "range" not some resolved value from some macro variable.&amp;nbsp;It is often a good strategy to program problematic code in simpler terms. &amp;nbsp;This creates 10 macro variables (range1 - range10) with no problem. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro x;
   %do i = 1 %to 10;
      %let range&amp;amp;i = &amp;amp;i;
      %end;
   %put _local_;   
   %mend;
%x

&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2017 18:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376128#M276571</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-07-14T18:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the Value of a Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376130#M276572</link>
      <description>&lt;P&gt;I kept playing around, and it turns out that using a DATA _NULL_ step will do the trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro vsrange;
   %do i=1 %to &amp;amp;cnt;
      %if %index(%substr(%str(&amp;amp;&amp;amp;range&amp;amp;i.),2,31),WEIGHT_U)&amp;gt;0 %then %do;
         data _null_;
            call symputx("&amp;amp;&amp;amp;range&amp;amp;i",%sysfunc(tranwrd(&amp;amp;&amp;amp;range&amp;amp;i.,WEIGHT_U,WEIGHTU)));
         run;
      %end;&lt;BR /&gt;   %end;
%mend vsrange;
%vsrange;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2017 18:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376130#M276572</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2017-07-14T18:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Changing the Value of a Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376131#M276573</link>
      <description>&lt;P&gt;Good point. &amp;nbsp;I could have probably gone that route, but I found another solution. &amp;nbsp;Thank you for your contribution though!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 18:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-the-Value-of-a-Macro-Variable/m-p/376131#M276573</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2017-07-14T18:27:35Z</dc:date>
    </item>
  </channel>
</rss>

