<?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 do loop symputx macro variable not resolving as desired in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193554#M36386</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the below code:&lt;/P&gt;&lt;P&gt;Options symbolgen mlogic mfile nomprint; &lt;/P&gt;&lt;P&gt;%macro bymonth;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;%do i = - &amp;amp;num_month %to 0;&lt;/P&gt;&lt;P&gt;call symputx('bymonth',put(intnx('month',"&amp;amp;date9"d,&amp;amp;i,'e'),date9.),'g');&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;%put &amp;amp;bymonth;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%bymonth;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm starting at - &amp;amp;num_month which is 5, date9 resolves to 16JUN2015.&amp;nbsp; My intent is to use the intnx to count back from -5 to 0 which will pull the complete year of data.&amp;nbsp; Date9 and i are resolving as I intend but &amp;amp;bymonth isn't changing with each iteration. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any guidance/help will be appreciated.&amp;nbsp; I'll paste some log below for your reading pleasure:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; Beginning execution.&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable NUM_MONTH resolves to 05&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %DO loop beginning; index variable I; start value is -5; stop value is 0; by value is 1.&amp;nbsp; &lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATE9 resolves to 16JUN2015&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable I resolves to -5&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %PUT &amp;amp;bymonth&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable BYMONTH resolves to 30JUN2015&lt;/P&gt;&lt;P&gt;30JUN2015&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %DO loop index variable I is now -4; loop will iterate again.&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATE9 resolves to 16JUN2015&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable I resolves to -4&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %PUT &amp;amp;bymonth&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable BYMONTH resolves to 30JUN2015&lt;/P&gt;&lt;P&gt;30JUN2015&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %DO loop index variable I is now -3; loop will iterate again.&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATE9 resolves to 16JUN2015&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable I resolves to -3&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %PUT &amp;amp;bymonth&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable BYMONTH resolves to 30JUN2015&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Jul 2015 13:58:20 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2015-07-01T13:58:20Z</dc:date>
    <item>
      <title>do loop symputx macro variable not resolving as desired</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193554#M36386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the below code:&lt;/P&gt;&lt;P&gt;Options symbolgen mlogic mfile nomprint; &lt;/P&gt;&lt;P&gt;%macro bymonth;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;%do i = - &amp;amp;num_month %to 0;&lt;/P&gt;&lt;P&gt;call symputx('bymonth',put(intnx('month',"&amp;amp;date9"d,&amp;amp;i,'e'),date9.),'g');&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;%put &amp;amp;bymonth;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%bymonth;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm starting at - &amp;amp;num_month which is 5, date9 resolves to 16JUN2015.&amp;nbsp; My intent is to use the intnx to count back from -5 to 0 which will pull the complete year of data.&amp;nbsp; Date9 and i are resolving as I intend but &amp;amp;bymonth isn't changing with each iteration. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any guidance/help will be appreciated.&amp;nbsp; I'll paste some log below for your reading pleasure:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; Beginning execution.&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable NUM_MONTH resolves to 05&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %DO loop beginning; index variable I; start value is -5; stop value is 0; by value is 1.&amp;nbsp; &lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATE9 resolves to 16JUN2015&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable I resolves to -5&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %PUT &amp;amp;bymonth&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable BYMONTH resolves to 30JUN2015&lt;/P&gt;&lt;P&gt;30JUN2015&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %DO loop index variable I is now -4; loop will iterate again.&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATE9 resolves to 16JUN2015&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable I resolves to -4&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %PUT &amp;amp;bymonth&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable BYMONTH resolves to 30JUN2015&lt;/P&gt;&lt;P&gt;30JUN2015&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %DO loop index variable I is now -3; loop will iterate again.&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable DATE9 resolves to 16JUN2015&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable I resolves to -3&lt;/P&gt;&lt;P&gt;MLOGIC(BYMONTH):&amp;nbsp; %PUT &amp;amp;bymonth&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable BYMONTH resolves to 30JUN2015&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jul 2015 13:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193554#M36386</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-07-01T13:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: do loop symputx macro variable not resolving as desired</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193555#M36387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another key piece of information:&amp;nbsp; these notes do not represent the first time you tried the macro.&amp;nbsp; The first time, you got messages about &amp;amp;BYMONTH not being resolved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The basic problem is that %PUT is not part of a DATA step, but CALL SYMPUTX only executes when the DATA step runs.&amp;nbsp; So the first time this ran, the order of execution of your statements was:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PUT&lt;/P&gt;&lt;P&gt;%PUT&lt;/P&gt;&lt;P&gt;%PUT&lt;/P&gt;&lt;P&gt;%PUT&lt;/P&gt;&lt;P&gt;%PUT&lt;/P&gt;&lt;P&gt;%PUT&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In fact, that's the order of execution every time, not just the first time.&amp;nbsp; But after the DATA step has run once, &amp;amp;BYMONTH exists and the %PUT statements can write it out.&amp;nbsp; This link may help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/publishing/2015/04/01/sas-authors-tip-macro-language-timing-is-everything/"&gt;http://blogs.sas.com/content/publishing/2015/04/01/sas-authors-tip-macro-language-timing-is-everything/&lt;/A&gt;&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>Wed, 01 Jul 2015 14:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193555#M36387</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-07-01T14:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: do loop symputx macro variable not resolving as desired</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193556#M36388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That did help.&amp;nbsp; I was getting the right answer but I wanted to see it before, I would have needed to make this update for the next step anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for pointing me in the right direction,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For anyone that searches for answers before asking the forum, here's the solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro bymonth;&lt;/P&gt;&lt;P&gt;%do i = &amp;amp;num_month %to 10;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symputx('bymonth',put(intnx('month',"&amp;amp;date9"d,&amp;amp;i,'e'),date9.),'g');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test&amp;amp;i;&lt;/P&gt;&lt;P&gt;test = substr("&amp;amp;bymonth",3,3);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%bymonth;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Jul 2015 15:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193556#M36388</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-07-01T15:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: do loop symputx macro variable not resolving as desired</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193557#M36389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;see also&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates" title="http://www.sascommunity.org/wiki/Macro_Loops_with_Dates"&gt;Macro Loops with Dates - sasCommunity&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 11:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-symputx-macro-variable-not-resolving-as-desired/m-p/193557#M36389</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-07-02T11:57:04Z</dc:date>
    </item>
  </channel>
</rss>

