<?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: Conditionally Modifying a Macro Variable within a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76956#M16623</link>
    <description>Hi Matt,&lt;BR /&gt;
&lt;BR /&gt;
It's the age old story. The difference between compilation time and execution time. Your %let will create the macro variable at compilation time (i.e. before any data has been run through, before the datastep has been executed). To update the value of a macro variable at execution time you need to use call symput.&lt;BR /&gt;
&lt;BR /&gt;
I would recommend looking up some documentation so that you understand it but basically what you need is:&lt;BR /&gt;
&lt;BR /&gt;
If var&amp;gt; &amp;amp;number then do;&lt;BR /&gt;
  call symput('Existing_Variable', &amp;amp;Existing_Variable+1);&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure it will like referencing itself. Why not create the count variable as a sas variable then use a call symput at the end to put that count value into your macro variable.</description>
    <pubDate>Fri, 13 Mar 2009 16:49:07 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-03-13T16:49:07Z</dc:date>
    <item>
      <title>Conditionally Modifying a Macro Variable within a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76955#M16622</link>
      <description>Hi all, &lt;BR /&gt;
I was wondering is it possible to conditionally modify an existing Macro Variable within a data step.  I am trying to do something like this within the data step:&lt;BR /&gt;
&lt;BR /&gt;
If var&amp;gt; &amp;amp;number then do;&lt;BR /&gt;
    %Let Existing_Variable=%EVAL(&amp;amp;Existing_Variable+1);&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
When I run that it appears to be modifying the macro variable &amp;amp;Existing_Variable even if the condition is not met.  Does anyone know how to do something like this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
&lt;BR /&gt;
~Matt</description>
      <pubDate>Fri, 13 Mar 2009 15:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76955#M16622</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-13T15:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Modifying a Macro Variable within a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76956#M16623</link>
      <description>Hi Matt,&lt;BR /&gt;
&lt;BR /&gt;
It's the age old story. The difference between compilation time and execution time. Your %let will create the macro variable at compilation time (i.e. before any data has been run through, before the datastep has been executed). To update the value of a macro variable at execution time you need to use call symput.&lt;BR /&gt;
&lt;BR /&gt;
I would recommend looking up some documentation so that you understand it but basically what you need is:&lt;BR /&gt;
&lt;BR /&gt;
If var&amp;gt; &amp;amp;number then do;&lt;BR /&gt;
  call symput('Existing_Variable', &amp;amp;Existing_Variable+1);&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure it will like referencing itself. Why not create the count variable as a sas variable then use a call symput at the end to put that count value into your macro variable.</description>
      <pubDate>Fri, 13 Mar 2009 16:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76956#M16623</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-13T16:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Modifying a Macro Variable within a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76957#M16624</link>
      <description>pznew, &lt;BR /&gt;
&lt;BR /&gt;
Thanks for the input.  I had thought about using the call symput but was hoping to get around using it.  I will go that route.  Thanks for the suggestion and help.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
~Matt</description>
      <pubDate>Fri, 13 Mar 2009 16:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76957#M16624</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-13T16:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Modifying a Macro Variable within a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76958#M16625</link>
      <description>You might also investigate the use of SYMGET/SYMGETN. Remember that &amp;amp;MACVAR references are ALSO resolved at COMPILE time and not EXECUTION time.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 13 Mar 2009 20:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76958#M16625</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-03-13T20:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally Modifying a Macro Variable within a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76959#M16626</link>
      <description>For your diagnostic, debugging experience, consider adding the following SAS code to your program to reveal code as it is compiled and executed:&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MLOGIC;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 13 Mar 2009 21:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-Modifying-a-Macro-Variable-within-a-data-step/m-p/76959#M16626</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-13T21:45:05Z</dc:date>
    </item>
  </channel>
</rss>

