<?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: Macro Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279713#M56405</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few issues that make it difficult to answer your question. First, do you agree that the semicolons are missing? Second, your question&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do I not need &amp;amp; in %last=first? first is a value and not reference. I dont understand it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;refers to code that isn't in your initial example. So we must assume, again, what you actually mean. In the line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let last=first&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the ampersand is technically not needed. You will howewever assign the text 'first' to variable last and that may not be what you want. So it may be functionally needed. In that case you will assign the value of first to last.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My advice: be clear in what you want to achieve and what your expected results are versus your actual results. You just leave too much guesswork for those that so clearly want to help you out in what is certainly a problem at beginners level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And use %PUT statements to check your results while experimenting. Simple but effective.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2016 11:48:09 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-06-23T11:48:09Z</dc:date>
    <item>
      <title>Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279364#M56296</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;here the task:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET first=yourname&lt;/P&gt;&lt;P&gt;%LET last=first&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;&amp;amp;&amp;amp;last;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the result in log?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279364#M56296</guid>
      <dc:creator>cons</dc:creator>
      <dc:date>2016-06-22T14:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279367#M56299</link>
      <description>&lt;P&gt;The result is an error message.&amp;nbsp; SAS statements have to end with a semicolon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you unable to test the code yourself?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279367#M56299</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-22T14:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279368#M56300</link>
      <description>&lt;P&gt;Hi. No you dont need ; if u define an macro variable.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279368#M56300</guid>
      <dc:creator>cons</dc:creator>
      <dc:date>2016-06-22T14:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279371#M56303</link>
      <description>&lt;P&gt;Hi its me again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know the result its vodername. But I dont understand why I need no &amp;amp; in Line 2 (%Last=first) If i want reference to macro variable first then I need zo type $first, right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279371#M56303</guid>
      <dc:creator>cons</dc:creator>
      <dc:date>2016-06-22T14:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279381#M56305</link>
      <description>&lt;P&gt;Its quite simple.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%PUT &amp;amp;&amp;amp;&amp;amp;last;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What happens when this goes into the macro pre-processor. &amp;nbsp;Well, it see's &amp;amp;last. which is a macro variable, so is de-references it to the text first. &amp;nbsp;Then it looks at the statement again:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%put &amp;amp;first;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which again is a macro variable, so it de-references it to be:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%put yourname;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which puts yourname in the log. &amp;nbsp;Not sure where you get "vodername" from as thats not in the test data.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just to confirm, you should put semi-colons after macro invocation otherwise it does not work,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;, is quite correct. &amp;nbsp;Also note, you should be putting "." after macro variables - whilst that is not required, it is good practice.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 15:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279381#M56305</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-22T15:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279382#M56306</link>
      <description>&lt;P&gt;You are quite correct&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;, these %let statements SHOULD have semicolons after them to avoid errors.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 15:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279382#M56306</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-22T15:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279391#M56311</link>
      <description>&lt;P&gt;Yes a lot's been said about the semicolons and such so no need for me to do the same. But did you try yourself? I must assume you have SAS at your disposal so just suck it and see. It;s sometimes so easy to answer your own question. What did you find?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: The correct answer is:&lt;/P&gt;
&lt;PRE&gt;ERROR: Open code statement recursion detected&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jun 2016 15:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279391#M56311</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-22T15:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279693#M56395</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for all answers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But you didnt talk about my question. Why do I not need &amp;amp; in %last=first? first is a value and not reference. I dont understand it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bye.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 08:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279693#M56395</guid>
      <dc:creator>cons</dc:creator>
      <dc:date>2016-06-23T08:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279695#M56397</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe I did above? &amp;nbsp;Maybe read the SAS documentation thoroughly on macro programming, this document may help also:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi22/CODERS/PAPER77.PDF" target="_blank"&gt;http://www2.sas.com/proceedings/sugi22/CODERS/PAPER77.PDF&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 08:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279695#M56397</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-23T08:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279713#M56405</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few issues that make it difficult to answer your question. First, do you agree that the semicolons are missing? Second, your question&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do I not need &amp;amp; in %last=first? first is a value and not reference. I dont understand it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;refers to code that isn't in your initial example. So we must assume, again, what you actually mean. In the line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let last=first&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the ampersand is technically not needed. You will howewever assign the text 'first' to variable last and that may not be what you want. So it may be functionally needed. In that case you will assign the value of first to last.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My advice: be clear in what you want to achieve and what your expected results are versus your actual results. You just leave too much guesswork for those that so clearly want to help you out in what is certainly a problem at beginners level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And use %PUT statements to check your results while experimenting. Simple but effective.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 11:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279713#M56405</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-23T11:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279716#M56407</link>
      <description>&lt;P&gt;You need to use an &amp;amp; when you want to trigger the macro processor to convert your macro variable reference to the value that it represents.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not add an &amp;amp; when defining the value of a macro variable in a %LET statement because that is how the %LET statement works. &amp;nbsp;The value before the equal sign is the name of the macro variable to create and the value after the equal is the value to assign to the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Also if you did add an &amp;amp; it would trigger the resolution of the macro variable reference and instead of defining a macro variable named LAST you would be asking the %LET statement to define a macro variable whose name is contained in the &amp;nbsp;existing macro variable named LAST. &amp;nbsp;That is actually a valid statement and useful in many situations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2016 12:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables/m-p/279716#M56407</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-06-23T12:25:40Z</dc:date>
    </item>
  </channel>
</rss>

