<?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 variable is assigned a value only after second run in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100324#M21035</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is because your 'ultimo' macro-variable isn't declared as global, and it is created within the macro 'ultimodato'. By declaring it as global (%global ultimo;), you will make it available to your call symput.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Florent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Jul 2012 14:36:37 GMT</pubDate>
    <dc:creator>Florent</dc:creator>
    <dc:date>2012-07-05T14:36:37Z</dc:date>
    <item>
      <title>Macro variable is assigned a value only after second run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100323#M21034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following piece of code, where I want the macro variable &amp;amp;ultimo to have a date value at the end. However, after running the code once, the value of &amp;amp;ulitmo is still missing, but after a second run, the value appears. My question is, what am I doing wrong with respect to making the code work doing its first run? Kind regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let year = 2012;&lt;BR /&gt;%let month = 06;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro ultimodato;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if %eval(&amp;amp;month) &amp;lt; 9 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let ultimo = 01/0%eval(&amp;amp;month.+1)/&amp;amp;year.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %if &amp;amp;month = 9 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let ultimo = 01/10/&amp;amp;year.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %if 9 &amp;lt; &amp;amp;month and &amp;amp;month &amp;lt; 12 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let ultimo = 01/%eval(&amp;amp;month.+1)/&amp;amp;year.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %if &amp;amp;month = 12 %then %do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let ultimo = 01/01/%eval(&amp;amp;year+1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;%mend ultimodato;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%ultimodato;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;call symput('ultimo',put(input("&amp;amp;ultimo",DDMMYY10.),date9.));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;ultimo;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 14:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100323#M21034</guid>
      <dc:creator>Hedegaard</dc:creator>
      <dc:date>2012-07-05T14:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable is assigned a value only after second run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100324#M21035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is because your 'ultimo' macro-variable isn't declared as global, and it is created within the macro 'ultimodato'. By declaring it as global (%global ultimo;), you will make it available to your call symput.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Florent&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 14:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100324#M21035</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2012-07-05T14:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable is assigned a value only after second run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100325#M21036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. It works. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 14:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100325#M21036</guid>
      <dc:creator>Hedegaard</dc:creator>
      <dc:date>2012-07-05T14:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable is assigned a value only after second run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100326#M21037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's the right answer to your original question.&amp;nbsp; But you should also consider whether or not you want to write a macro for this purpose.&amp;nbsp; The DATA step already has functions that will do the work for you.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symput('ultimo', put( intnx('month', mdy(&amp;amp;month, 1, &amp;amp;year), +1), date9.));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 14:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100326#M21037</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-07-05T14:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable is assigned a value only after second run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100327#M21038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding, I didn't know you could do that! Thanks. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2012 07:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-is-assigned-a-value-only-after-second-run/m-p/100327#M21038</guid>
      <dc:creator>Hedegaard</dc:creator>
      <dc:date>2012-07-06T07:34:29Z</dc:date>
    </item>
  </channel>
</rss>

