<?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 resolution causing invalid statement (appears to be outputting list) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480535#M124205</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;The above code is actually (an altered) part of a custom transform in DI Studio, hence the use of the macros to cater for the variable amount of attributes that can be lagged by variable amounts.&lt;/P&gt;&lt;P&gt;I've actually moved the do loop into&amp;nbsp;the rename&amp;nbsp;statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A lot is left out of the posted code to focus on the resolution issue that I had.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you have another method&amp;nbsp;that would slot nicely into a custom transform, I'd definitely be interested in seeing it,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the interest in the question!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jul 2018 17:09:36 GMT</pubDate>
    <dc:creator>DTFX-JJ</dc:creator>
    <dc:date>2018-07-23T17:09:36Z</dc:date>
    <item>
      <title>Macro variable resolution causing invalid statement (appears to be outputting list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480386#M124155</link>
      <description>&lt;P&gt;Hi all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've hit a snag where my macro variables resolve correctly, but seem to resolve to a list in-between, causing incorrect output and an invalid statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below is what I'm currently trying:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option mprint symbolgen mlogic;
%macro test;
	%let LAG_VARS = TEST_LAG_VAR_1_ TEST_LAG_VAR_2_;
	%let LAG_VARS_count = 2;
	%let LAG_VARS0 = 1;
	%let LAG_VARS1 = TEST_LAG_VAR_1_;
	%let LAG_VARS2 = TEST_LAG_VAR_2_;
	%let LAG_MONTHS_count = %nrquote(1);
	%let LAG_MONTHS = %nrquote(12);
	%let LAG_MONTHS1 = %nrquote(12);

	%if &amp;amp;LAG_VARS_count &amp;gt; 0 %then %do;
		%do lag_months_loop=1 %to &amp;amp;LAG_MONTHS_count;
			data extract_lag_3;
			%do lag_vars_loop=1 %to &amp;amp;LAG_VARS_count;
				&amp;amp;&amp;amp;lag_vars&amp;amp;lag_vars_loop.._L&amp;amp;&amp;amp;LAG_MONTHS&amp;amp;lag_months_loop..=&amp;amp;&amp;amp;lag_vars&amp;amp;lag_vars_loop..;
			%end;
		%end;
	%end;
%mend;
%test;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;produces the following log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;MLOGIC(TEST): Beginning execution.&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_VARS)&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_VARS_COUNT)&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_VARS0)&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_VARS1)&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_VARS2)&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_MONTHS_COUNT)&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_MONTHS)&lt;BR /&gt;MLOGIC(TEST): %LET (variable name is LAG_MONTHS1)&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS_COUNT resolves to 2&lt;BR /&gt;2 The SAS System 13:23 Friday, July 20, 2018&lt;/P&gt;&lt;P&gt;MLOGIC(TEST): %IF condition &amp;amp;LAG_VARS_count &amp;gt; 0 is TRUE&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_MONTHS_COUNT resolves to 1&lt;BR /&gt;SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.&lt;BR /&gt;MLOGIC(TEST): %DO loop beginning; index variable LAG_MONTHS_LOOP; start value is 1; stop value is 1; by value is 1.&lt;BR /&gt;MPRINT(TEST): data extract_lag_3;&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS_COUNT resolves to 2&lt;BR /&gt;MLOGIC(TEST): %DO loop beginning; index variable LAG_VARS_LOOP; start value is 1; stop value is 2; by value is 1.&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS_LOOP resolves to 1&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_MONTHS_LOOP resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS1 resolves to TEST_LAG_VAR_1_&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_MONTHS1 resolves to 12&lt;BR /&gt;SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.&lt;BR /&gt;NOTE: Line generated by the macro variable "LAG_MONTHS1".&lt;BR /&gt;45 TEST_LAG_VAR_1__L12&lt;BR /&gt;_________________&lt;BR /&gt;180&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS_LOOP resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS1 resolves to TEST_LAG_VAR_1_&lt;BR /&gt;MPRINT(TEST): TEST_LAG_VAR_1__L12=TEST_LAG_VAR_1_;&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable LAG_VARS_LOOP is now 2; loop will iterate again.&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS_LOOP resolves to 2&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_MONTHS_LOOP resolves to 1&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS2 resolves to TEST_LAG_VAR_2_&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_MONTHS1 resolves to 12&lt;BR /&gt;SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.&lt;BR /&gt;NOTE: Line generated by the macro variable "LAG_MONTHS1".&lt;BR /&gt;45 TEST_LAG_VAR_2__L12&lt;BR /&gt;_________________&lt;BR /&gt;180&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS_LOOP resolves to 2&lt;BR /&gt;SYMBOLGEN: Macro variable LAG_VARS2 resolves to TEST_LAG_VAR_2_&lt;BR /&gt;MPRINT(TEST): TEST_LAG_VAR_2__L12=TEST_LAG_VAR_2_;&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable LAG_VARS_LOOP is now 3; loop will not iterate again.&lt;BR /&gt;MLOGIC(TEST): %DO loop index variable LAG_MONTHS_LOOP is now 2; loop will not iterate again.&lt;BR /&gt;MLOGIC(TEST): Ending execution.&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It feels like it's resolving&amp;nbsp;it in such a way that it outputs a list somehow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how to resolve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks -JJ&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 10:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480386#M124155</guid>
      <dc:creator>DTFX-JJ</dc:creator>
      <dc:date>2018-07-23T10:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution causing invalid statement (appears to be outputting list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480388#M124156</link>
      <description>&lt;P&gt;Seems like it was a simple fix!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i stumbled upon this post&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/macro-variable-resolution-ampersand-with-underscore/m-p/159773#M41640" target="_self"&gt;https://communities.sas.com/t5/SAS-Procedures/macro-variable-resolution-ampersand-with-underscore/m-p/159773#M41640&lt;/A&gt;&amp;nbsp;that used %unquote(). I used it in mine (and fixed the missing run;) as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogicnest mprintnest mlogic mprint symbolgen;
%macro test;
	%let LAG_VARS = TEST_LAG_VAR_1_ TEST_LAG_VAR_2_;
	%let LAG_VARS_count = 2;
	%let LAG_VARS0 = 1;
	%let LAG_VARS1 = TEST_LAG_VAR_1_;
	%let LAG_VARS2 = TEST_LAG_VAR_2_;
	%let LAG_MONTHS_count = %nrquote(1);
	%let LAG_MONTHS = %nrquote(12);
	%let LAG_MONTHS1 = %nrquote(12);

	%if &amp;amp;LAG_VARS_count &amp;gt; 0 %then %do;
		%do lag_months_loop=1 %to &amp;amp;LAG_MONTHS_count;
			data extract_lag_3;
			%do lag_vars_loop=1 %to &amp;amp;LAG_VARS_count;
				%unquote(&amp;amp;&amp;amp;lag_vars&amp;amp;lag_vars_loop.._L&amp;amp;&amp;amp;LAG_MONTHS&amp;amp;lag_months_loop..)=&amp;amp;&amp;amp;lag_vars&amp;amp;lag_vars_loop..;
			%end;
			run;
		%end;
	%end;
%mend;
%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 10:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480388#M124156</guid>
      <dc:creator>DTFX-JJ</dc:creator>
      <dc:date>2018-07-23T10:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution causing invalid statement (appears to be outputting list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480398#M124159</link>
      <description>&lt;P&gt;I have to ask, why are you trying to do all this in macro in the first place?&amp;nbsp; Base SAS is the programming language, you have just used messy macro to generate Base SAS?&amp;nbsp; I mean just at a guess you could reduce&amp;nbsp;your code by using lag() function, or retained variables, the do loop can be in plain datastep, and the whole macro test bit seems just there to allow a %do loop, which datastep can do with do.&amp;nbsp; Admittedly its very hard to read that code with all the mixed case coding and &amp;amp;&amp;amp;&amp;amp;&amp;amp;'s.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 12:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480398#M124159</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-23T12:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution causing invalid statement (appears to be outputting list)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480535#M124205</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;The above code is actually (an altered) part of a custom transform in DI Studio, hence the use of the macros to cater for the variable amount of attributes that can be lagged by variable amounts.&lt;/P&gt;&lt;P&gt;I've actually moved the do loop into&amp;nbsp;the rename&amp;nbsp;statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A lot is left out of the posted code to focus on the resolution issue that I had.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you have another method&amp;nbsp;that would slot nicely into a custom transform, I'd definitely be interested in seeing it,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the interest in the question!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 17:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-causing-invalid-statement-appears-to/m-p/480535#M124205</guid>
      <dc:creator>DTFX-JJ</dc:creator>
      <dc:date>2018-07-23T17:09:36Z</dc:date>
    </item>
  </channel>
</rss>

