<?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 execution: ERROR 180-322: Statement is not valid or it is used out of proper order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331696#M271931</link>
    <description>&lt;P&gt;I ouput the code to a file as you suggested and here is what the macro ouput:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc model data = model_data_estimation;
parms intercept 0 b1 0 rho1 0;
y = rho1*lag(y) + (intercept + b1 * x) - rho1*lag(intercept + b1 * x);
whitened_x = x - rho1 * LAG(x);
fit y / BREUSCH=(1 whitened_x);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which is exactly what I want. I ran this code and it works fine with no errors. So I still don't understand why I am getting an error when it runs through the macro. I am really at a loss here. Any ideas? I have a ton of these models to run so it would take a while to write these out manually.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2017 21:03:45 GMT</pubDate>
    <dc:creator>ntn4jg</dc:creator>
    <dc:date>2017-02-10T21:03:45Z</dc:date>
    <item>
      <title>Macro execution: ERROR 180-322: Statement is not valid or it is used out of proper order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331643#M271929</link>
      <description>&lt;P&gt;I have a macro that creates a model for me to test heteroskedasticity on whitened residuals and exogenous variables. However, I get the error that the statements is not valid. I have the macro printing out what it is doing and if I take the print out and paste it into a SAS file it runs with no problem. So why is it giving me this error when I run it through the macro?? Here is my log output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;MPRINT(COCHRANE_ORCUTT):   proc model data = model_data_estimation;
MPRINT(COCHRANE_ORCUTT):   parms intercept 0 b1 0 rho1 0;
MPRINT(COCHRANE_ORCUTT):   y = rho1*lag(y) + (intercept + b1 * x) - rho1*lag(intercept + b1 *x);
NOTE: Line generated by the macro variable "WHITENEDVAR".
1            whitened_x
             --
             180
MPRINT(COCHRANE_ORCUTT):   whitened_x = x - rho1 * LAG(x);
MPRINT(COCHRANE_ORCUTT):   fit y / BREUSCH=(1 whitened_x);
MPRINT(COCHRANE_ORCUTT):   run;

ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the snippet of the macro code:&lt;/P&gt;&lt;PRE&gt;%let whitened_vars = ;
		%let count=1;
			%let word=%qscan(&amp;amp;iv, &amp;amp;count, %str( ));
    		%do %while(&amp;amp;word ne);     
       		 %let word=%qscan(&amp;amp;iv, &amp;amp;count, %str( )); 
				%if(&amp;amp;word ne) %then %do;
					%let count=%eval(&amp;amp;count+1);
					%let whitened_vars = &amp;amp;whitened_vars whitened_&amp;amp;word;
				%end;
    		%end;
			
			%put &amp;amp;whitened_vars;
		proc model data = &amp;amp;data;
			parms &amp;amp;parameters;
			&amp;amp;modelspec;
			%let count=1;
			%let word=%qscan(&amp;amp;iv, &amp;amp;count, %str( ));
    		%do %while(&amp;amp;word ne);     
       		 %let word=%qscan(&amp;amp;iv, &amp;amp;count, %str( )); 
				%if(&amp;amp;word ne) %then %do;
					%let count=%eval(&amp;amp;count+1);
					%let whitenedvar = whitened_&amp;amp;word;
					&amp;amp;whitenedvar = &amp;amp;word - rho1 * LAG(&amp;amp;word);
				%end;
    		%end;
			
			fit &amp;amp;y / BREUSCH=(1 &amp;amp;whitened_vars);
		run;
	%end;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2017 19:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331643#M271929</guid>
      <dc:creator>ntn4jg</dc:creator>
      <dc:date>2017-02-10T19:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro execution: ERROR 180-322: Statement is not valid or it is used out of proper order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331675#M271930</link>
      <description>&lt;P&gt;You tried using MPRINT when running a macro, and then copying the generated code from the sas log to a SAS program for retesting, which did not reproduce the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest going&amp;nbsp;one step further in the test.&amp;nbsp; Use&amp;nbsp;the MFILE option as well as the MPRINT option.&amp;nbsp; This will write the generated macro code to a file, ready for re-running.&amp;nbsp; Not sas log notes or similar stuff to edit out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint &lt;FONT style="background-color: rgb(252, 222, 192);"&gt;mfile&lt;/FONT&gt;;&lt;BR /&gt;filename mprint 'TEMPOUT';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Running your code after this will write exactly what the sas macro processor produced to TEMPOUT.&amp;nbsp;&amp;nbsp; You can then run that code and get exact line numbers for any error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 20:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331675#M271930</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-10T20:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro execution: ERROR 180-322: Statement is not valid or it is used out of proper order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331696#M271931</link>
      <description>&lt;P&gt;I ouput the code to a file as you suggested and here is what the macro ouput:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc model data = model_data_estimation;
parms intercept 0 b1 0 rho1 0;
y = rho1*lag(y) + (intercept + b1 * x) - rho1*lag(intercept + b1 * x);
whitened_x = x - rho1 * LAG(x);
fit y / BREUSCH=(1 whitened_x);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which is exactly what I want. I ran this code and it works fine with no errors. So I still don't understand why I am getting an error when it runs through the macro. I am really at a loss here. Any ideas? I have a ton of these models to run so it would take a while to write these out manually.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 21:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331696#M271931</guid>
      <dc:creator>ntn4jg</dc:creator>
      <dc:date>2017-02-10T21:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro execution: ERROR 180-322: Statement is not valid or it is used out of proper order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331769#M271932</link>
      <description>&lt;P&gt;Well, this isn't a solution to the particular problem you're encountering, but it is something to watch for down the road. &amp;nbsp;Long variable names will cause a problem. &amp;nbsp;When your variable name is X you generate WHITENED_X= which is fine. &amp;nbsp;But if your variable name were 24 characters or longer, there wouldn't be room to prefix it with WHITENED_ and still remain within SAS's 32-character limit for variable names.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Feb 2017 02:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331769#M271932</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-11T02:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro execution: ERROR 180-322: Statement is not valid or it is used out of proper order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331802#M271933</link>
      <description>&lt;P&gt;In the situation that you decscribe (macro is producing correct code in the log but erroring at a valid statement), usually (always?) the problem is the macro language failed to unquote something.&amp;nbsp; Macro quoting symbols are supposed to be automatically unquoted before they get to SAS compiler, and it they aren't, they can cause problems.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are using %QSCAN, you are using macro quoting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would replace this part of your macro that returns SAS code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;whitenedvar = &amp;amp;word - rho1 * LAG(&amp;amp;word);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%unquote(&amp;amp;whitenedvar) = &amp;amp;word - rho1 * LAG(&amp;amp;word);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And see if that fixes it, or at least changes the error you get.&amp;nbsp; It's possible &amp;amp;word will also need to be unquoted, so you could also try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%unquote(&amp;amp;whitenedvar) = %unquote(&amp;amp;word) - rho1 * LAG(%unquote(&amp;amp;word));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Feb 2017 12:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-execution-ERROR-180-322-Statement-is-not-valid-or-it-is/m-p/331802#M271933</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-02-11T12:53:56Z</dc:date>
    </item>
  </channel>
</rss>

