<?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: Resolving macro variable from within a data step in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Resolving-macro-variable-from-within-a-data-step/m-p/592493#M15364</link>
    <description>&lt;P&gt;You're absolutely right, there are other ways of attacking this which I should have tried.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the solution &lt;STRONG&gt;&lt;EM&gt;and the explanation&lt;/EM&gt;.&amp;nbsp; &lt;/STRONG&gt;This helps me out quite a bit!&amp;nbsp; Thanks, again.&amp;nbsp; -- George&lt;/P&gt;</description>
    <pubDate>Sun, 29 Sep 2019 18:06:46 GMT</pubDate>
    <dc:creator>grezek</dc:creator>
    <dc:date>2019-09-29T18:06:46Z</dc:date>
    <item>
      <title>Resolving macro variable from within a data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-macro-variable-from-within-a-data-step/m-p/592479#M15361</link>
      <description>&lt;P&gt;I want to create/assign macro variables&amp;nbsp;by &amp;nbsp;adding and substracting variables in the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any&amp;nbsp;suggestions would be appreciated.&amp;nbsp; Thank you.&amp;nbsp; -- George&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code and dataset are attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;libname&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; sasdb &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"C:\grezek\CRE CECL"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;data&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2016Q4'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017Q1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d3'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017Q2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d4'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017Q3'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d5'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017Q4'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d6'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2018Q1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d7'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2018Q2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d8'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2018Q3'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d9'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2018Q4'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d10'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2019Q1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;options&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;symbolgen&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; macrogen &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;mprint&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &lt;STRONG&gt;&lt;I&gt;amort&lt;/I&gt;&lt;/STRONG&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; amort2_&amp;amp;&amp;amp;d&amp;amp;i = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysevalf&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(amort_&amp;amp;&amp;amp;d&amp;amp;i.. + Net_financial_amount_&amp;amp;&amp;amp;d&amp;amp;i.. - Net_financial_amount_next_&amp;amp;&amp;amp;d&amp;amp;i..) ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; sasdb.header_amort3 ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; sasdb.header_amort2 ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;amort&lt;/I&gt;&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log is (although I've tried quite of number of alternative, none seem to make the macro variable resolve to numbers):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;83 libname sasdb "C:\grezek\CRE CECL" ;&lt;/P&gt;&lt;P&gt;NOTE: Libref SASDB was successfully assigned as follows:&lt;/P&gt;&lt;P&gt;Engine: V9&lt;/P&gt;&lt;P&gt;Physical Name: C:\grezek\CRE CECL&lt;/P&gt;&lt;P&gt;83 ! data _null_ ;&lt;/P&gt;&lt;P&gt;84 call symputx('d1','2016Q4');&lt;/P&gt;&lt;P&gt;85 call symputx('d2','2017Q1');&lt;/P&gt;&lt;P&gt;86 call symputx('d3','2017Q2');&lt;/P&gt;&lt;P&gt;87 call symputx('d4','2017Q3');&lt;/P&gt;&lt;P&gt;88 call symputx('d5','2017Q4');&lt;/P&gt;&lt;P&gt;89 call symputx('d6','2018Q1');&lt;/P&gt;&lt;P&gt;90 call symputx('d7','2018Q2');&lt;/P&gt;&lt;P&gt;91 call symputx('d8','2018Q3');&lt;/P&gt;&lt;P&gt;92 call symputx('d9','2018Q4');&lt;/P&gt;&lt;P&gt;93 call symputx('d10','2019Q1');&lt;/P&gt;&lt;P&gt;94 options symbolgen macrogen mprint ;&lt;/P&gt;&lt;P&gt;95&lt;/P&gt;&lt;P&gt;96 %macro amort ;&lt;/P&gt;&lt;P&gt;97&lt;/P&gt;&lt;P&gt;98 %do i = 1 %to 10 ;&lt;/P&gt;&lt;P&gt;99 %let amort2_&amp;amp;&amp;amp;d&amp;amp;i = %sysevalf(amort_&amp;amp;&amp;amp;d&amp;amp;i.. + Net_financial_amount_&amp;amp;&amp;amp;d&amp;amp;i.. -&lt;/P&gt;&lt;P&gt;99 ! Net_financial_amount_next_&amp;amp;&amp;amp;d&amp;amp;i..) ;&lt;/P&gt;&lt;P&gt;100 %end ;&lt;/P&gt;&lt;P&gt;101 run ;&lt;/P&gt;&lt;P&gt;102 %mend ;&lt;/P&gt;&lt;P&gt;103 run ;&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.01 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;104&lt;/P&gt;&lt;P&gt;105 data sasdb.header_amort3 ;&lt;/P&gt;&lt;P&gt;106 set sasdb.header_amort2 ;&lt;/P&gt;&lt;P&gt;107&lt;/P&gt;&lt;P&gt;108 %amort ;&lt;/P&gt;&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable D1 resolves to 2016Q4&lt;/P&gt;&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable D1 resolves to 2016Q4&lt;/P&gt;&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable D1 resolves to 2016Q4&lt;/P&gt;&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 1&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable D1 resolves to 2016Q4&lt;/P&gt;&lt;P&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;/P&gt;&lt;P&gt;operand is required. The condition was: amort_2016Q4 + Net_financial_amount_2016Q4 -&lt;/P&gt;&lt;P&gt;Net_financial_amount_next_2016Q4&lt;/P&gt;&lt;P&gt;ERROR: The macro AMORT will stop executing.&lt;/P&gt;&lt;P&gt;109 run ;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;WARNING: The data set SASDB.HEADER_AMORT3 may be incomplete. When this step was stopped there&lt;/P&gt;&lt;P&gt;were 0 observations and 28 variables.&lt;/P&gt;&lt;P&gt;WARNING: Data set SASDB.HEADER_AMORT3 was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.01 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2019 13:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-macro-variable-from-within-a-data-step/m-p/592479#M15361</guid>
      <dc:creator>grezek</dc:creator>
      <dc:date>2019-09-29T13:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving macro variable from within a data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-macro-variable-from-within-a-data-step/m-p/592480#M15362</link>
      <description>&lt;P&gt;You could do this whole thing with ARRAYs and not ever have to use a macro or macro variable, and not ever have the complications that you are running into with macro variables. Simplify, that would be a good thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, %SYSEVALF expects macro variables, not data step variables. I assume that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;amort_2016Q4 + Net_financial_amount_2016Q4 - Net_financial_amount_next_2016Q4&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;refer to data step variables. Since you appear to want to add or subtract these data step variables, you could do this with data step commands (which adds or subtracts data step variables) and not with the macro function %SYSEVALF (which adds or subtracts macro variables):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i = 1 %to 10 ;

amort2_&amp;amp;&amp;amp;d&amp;amp;i = amort_&amp;amp;&amp;amp;d&amp;amp;i.. + Net_financial_amount_&amp;amp;&amp;amp;d&amp;amp;i.. - Net_financial_amount_next_&amp;amp;&amp;amp;d&amp;amp;i.. ;

%end ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember, macro variables, when resolved must produce legal valid SAS code, and if you first create legal valid SAS code without macros and without macro variables for one or two cases, once you have that working, you could more easily make a macro work. If you don't have the code working without macro variables and without macros, you will never get it to work with macros. Or, as I strongly advise, use ARRAYs and not macros.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2019 16:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-macro-variable-from-within-a-data-step/m-p/592480#M15362</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-29T16:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Resolving macro variable from within a data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Resolving-macro-variable-from-within-a-data-step/m-p/592493#M15364</link>
      <description>&lt;P&gt;You're absolutely right, there are other ways of attacking this which I should have tried.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the solution &lt;STRONG&gt;&lt;EM&gt;and the explanation&lt;/EM&gt;.&amp;nbsp; &lt;/STRONG&gt;This helps me out quite a bit!&amp;nbsp; Thanks, again.&amp;nbsp; -- George&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2019 18:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Resolving-macro-variable-from-within-a-data-step/m-p/592493#M15364</guid>
      <dc:creator>grezek</dc:creator>
      <dc:date>2019-09-29T18:06:46Z</dc:date>
    </item>
  </channel>
</rss>

