<?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 not resolving the way I intend in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217173#M39997</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your SAS macro variable &amp;amp;YEAR is right-justified and has leading blanks resulting in an invalid concatenated macro variable with the %LET.&amp;nbsp; Consider how/where &amp;amp;YEAR is assigned and if using a %SYSFUNC(PUTN(...)) then add a -L appending as the second argument to PUT, indicating a left-justified result/assignment).&amp;nbsp; Otherwise share your SAS-log result as it appears your SET statement is not formatted properly (surmised based on the ERROR).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;/P&gt;&lt;P&gt;SBBWorks, Inc.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Jun 2015 20:50:02 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2015-06-30T20:50:02Z</dc:date>
    <item>
      <title>macro variables not resolving the way I intend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217169#M39993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a macro that should collect data through last month for the year.&amp;nbsp; Eventually I'll be adding a section to add last year plus this year until last month but I'm not there yet.&amp;nbsp; The code I have is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Options symbolgen mlogic mfile; &lt;/P&gt;&lt;P&gt;%macro new_tran;&lt;/P&gt;&lt;P&gt;data new_tran;&lt;/P&gt;&lt;P&gt;set&lt;/P&gt;&lt;P&gt;%do i = 01 %to &amp;amp;num_month; &lt;/P&gt;&lt;P&gt;%let val=%sysfunc(putn(&amp;amp;i,z2.));&lt;/P&gt;&lt;P&gt;newtran.pid_defaults_final_&amp;amp;&amp;amp;val&amp;amp;year;&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;%new_tran;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A portion of the log that I'm getting hung up is below, it looks like the macro variables are resolving with a space in between them.&amp;nbsp; I tried to use sysfunc with catx but that was not successful.&amp;nbsp; Any help is appreciated:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;MPRINT(NEW_TRAN):&amp;nbsp;&amp;nbsp; set newtran.pid_defaults_final_01 2015;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ERROR: File NEWTRAN.PID_DEFAULTS_FINAL_01.DATA does not exist.&lt;/P&gt;&lt;P&gt;MLOGIC(NEW_TRAN):&amp;nbsp; %DO loop index variable I is now 2; loop will iterate again.&lt;/P&gt;&lt;P&gt;MLOGIC(NEW_TRAN):&amp;nbsp; %LET (variable name is VAL)&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The SAS System&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 09:21 Tuesday, June 30, 2015&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable I resolves to 2&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable YEAR resolves to&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2015&lt;/P&gt;&lt;P&gt;SYMBOLGEN:&amp;nbsp; Macro variable VAL resolves to 02&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "VAL".&lt;/P&gt;&lt;P&gt;33&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newtran.pid_defaults_final_02&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 19:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217169#M39993</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-30T19:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro variables not resolving the way I intend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217170#M39994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For set statements you can use short cuts with the colon operator or - symbol.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Set all tables that start with pid_defaults&lt;/P&gt;&lt;P&gt;Set newtran.pid_defaults: ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your code generates an error to me, since it's looking for a macro variable val012015 with the double &amp;amp;&amp;amp; symbol.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This doesn't generate any spaces for me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro new_tran (num_month=12, year=2015);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i = 01 %to &amp;amp;num_month;&lt;/P&gt;&lt;P&gt;%let val=%sysfunc(putn(&amp;amp;i,z2.));&lt;/P&gt;&lt;P&gt;%put pid_defaults_final_&amp;amp;val.&amp;amp;year;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%new_tran;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 20:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217170#M39994</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-06-30T20:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: macro variables not resolving the way I intend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217171#M39995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I added strip to where I initiate the macro variable and I get the same error that you do, making the change to &amp;amp;var.&amp;amp;year seemed to work.&amp;nbsp; Any reason why the &amp;amp;&amp;amp;var&amp;amp;year doesn't work the way I am intending?&amp;nbsp; But after looking at the output I am only getting one dataset as input where I expect 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get an error when getting to the second input dataset:&lt;/P&gt;&lt;P&gt;newtran.pid_defaults_final_022015&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _________________________________&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 557&lt;/P&gt;&lt;P&gt;ERROR: DATA STEP Component Object failure.&amp;nbsp; Aborted during the COMPILATION phase.&lt;/P&gt;&lt;P&gt;ERROR 557-185: Variable newtran is not an object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've checked and the input is valid, it works without the macro, but I'm not sure how to correct the macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 20:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217171#M39995</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-30T20:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: macro variables not resolving the way I intend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217172#M39996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You're missing a semicolon after the last SET statement is my guess...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try adding a %put %str(;); after your loop or another explicit semicolon.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 20:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217172#M39996</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-06-30T20:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: macro variables not resolving the way I intend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217173#M39997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your SAS macro variable &amp;amp;YEAR is right-justified and has leading blanks resulting in an invalid concatenated macro variable with the %LET.&amp;nbsp; Consider how/where &amp;amp;YEAR is assigned and if using a %SYSFUNC(PUTN(...)) then add a -L appending as the second argument to PUT, indicating a left-justified result/assignment).&amp;nbsp; Otherwise share your SAS-log result as it appears your SET statement is not formatted properly (surmised based on the ERROR).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;/P&gt;&lt;P&gt;SBBWorks, Inc.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 20:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217173#M39997</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-06-30T20:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: macro variables not resolving the way I intend</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217174#M39998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That did it, now that it's there it seems obviously necessary but I didn't think it through.&amp;nbsp; Thanks for the help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro new_tran;&lt;/P&gt;&lt;P&gt;data new_tran;&lt;/P&gt;&lt;P&gt;set&lt;/P&gt;&lt;P&gt;%do i = 01 %to &amp;amp;num_month; &lt;/P&gt;&lt;P&gt;%let val=%sysfunc(putn(&amp;amp;i,z2.));&lt;/P&gt;&lt;P&gt;newtran.pid_defaults_final_&amp;amp;val.&amp;amp;year &lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%new_tran;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 20:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variables-not-resolving-the-way-I-intend/m-p/217174#M39998</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-30T20:51:51Z</dc:date>
    </item>
  </channel>
</rss>

