<?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 ERROR 180-322: Statement is not valid or it is used out of proper order. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-180-322-Statement-is-not-valid-or-it-is-used-out-of-proper/m-p/741362#M38799</link>
    <description>&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm coding a macro to create all the month-year between two dates and concatenate them with a string.&lt;/P&gt;&lt;P&gt;When I write it without macro, it works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%let start_date=01jan2013;
	%let end_date=01dec2019;
	%let mylib = "SCCOMOTR.Vinculacion2_";
	data want_date;
		date="&amp;amp;start_date"d;

		do while (date&amp;lt;="&amp;amp;end_date"d);
			output;
			date=intnx('month', date, 1, 's');
		end;

		format date YYMMN6.;
	run;

	data want_date;
		set want_date;
		new_var= &amp;amp;mylib ||  put(date,YYMMN6.);
	run;

	PROC SQL;
		SELECT new_var INTO :output SEPARATED BY " "
			FROM want_date;
	QUIT;
%put &amp;amp;output.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but when I want to convert it to a macro, it fails:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO createStringWithTables (start_date, end_date, mylib);

	%global output;

		data want_date;
		date="&amp;amp;start_date"d;

		%do %while (date&amp;lt;="&amp;amp;end_date"d);
			output;
			date=intnx('month', date, 1, 's');
		%end;

		format date YYMMN6.;
	run;

	data want_date;
		set want_date;
		new_var= &amp;amp;mylib ||  put(date,YYMMN6.);
	run;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;	PROC SQL;
		SELECT new_var INTO :output SEPARATED BY " "
			FROM want_date;
	QUIT;
%mend;

%createStringWithTables(01jan2010, 01dec2019, BaseDeDades_)&lt;/CODE&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rotmo86_1-1620981876502.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59393iC99F098DCD6889FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rotmo86_1-1620981876502.png" alt="rotmo86_1-1620981876502.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Could you help me to find the bug?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Fri, 14 May 2021 08:46:22 GMT</pubDate>
    <dc:creator>rotmo86</dc:creator>
    <dc:date>2021-05-14T08:46:22Z</dc:date>
    <item>
      <title>ERROR 180-322: Statement is not valid or it is used out of proper order.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-180-322-Statement-is-not-valid-or-it-is-used-out-of-proper/m-p/741362#M38799</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm coding a macro to create all the month-year between two dates and concatenate them with a string.&lt;/P&gt;&lt;P&gt;When I write it without macro, it works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%let start_date=01jan2013;
	%let end_date=01dec2019;
	%let mylib = "SCCOMOTR.Vinculacion2_";
	data want_date;
		date="&amp;amp;start_date"d;

		do while (date&amp;lt;="&amp;amp;end_date"d);
			output;
			date=intnx('month', date, 1, 's');
		end;

		format date YYMMN6.;
	run;

	data want_date;
		set want_date;
		new_var= &amp;amp;mylib ||  put(date,YYMMN6.);
	run;

	PROC SQL;
		SELECT new_var INTO :output SEPARATED BY " "
			FROM want_date;
	QUIT;
%put &amp;amp;output.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but when I want to convert it to a macro, it fails:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO createStringWithTables (start_date, end_date, mylib);

	%global output;

		data want_date;
		date="&amp;amp;start_date"d;

		%do %while (date&amp;lt;="&amp;amp;end_date"d);
			output;
			date=intnx('month', date, 1, 's');
		%end;

		format date YYMMN6.;
	run;

	data want_date;
		set want_date;
		new_var= &amp;amp;mylib ||  put(date,YYMMN6.);
	run;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;	PROC SQL;
		SELECT new_var INTO :output SEPARATED BY " "
			FROM want_date;
	QUIT;
%mend;

%createStringWithTables(01jan2010, 01dec2019, BaseDeDades_)&lt;/CODE&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rotmo86_1-1620981876502.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59393iC99F098DCD6889FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rotmo86_1-1620981876502.png" alt="rotmo86_1-1620981876502.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Could you help me to find the bug?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 08:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-180-322-Statement-is-not-valid-or-it-is-used-out-of-proper/m-p/741362#M38799</guid>
      <dc:creator>rotmo86</dc:creator>
      <dc:date>2021-05-14T08:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 180-322: Statement is not valid or it is used out of proper order.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-180-322-Statement-is-not-valid-or-it-is-used-out-of-proper/m-p/741365#M38800</link>
      <description>&lt;P&gt;Please paste the log entries into a Text box on the forum opened with the &amp;lt;/&amp;gt; icon. Then we can much more easily make corrections and paste corrected code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your Picture of the error shows that this is generated by a MACRO you need to do one of two things, and better is both:&lt;/P&gt;
&lt;P&gt;1) Provide the Code to the macro including the call to that macro.&lt;/P&gt;
&lt;P&gt;2) One of the general debugging options for macro issues is to set the OPTION MPRINT; before running the macro so get details about the code generated by the macro. Then copy the entire log from running the macro and paste that whole mess into a text box on the forum&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Used out of order" often means that lines before what you have shown actually caused the issue. In fact, many errors can be caused by previous lines.&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 09:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-180-322-Statement-is-not-valid-or-it-is-used-out-of-proper/m-p/741365#M38800</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-14T09:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 180-322: Statement is not valid or it is used out of proper order.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-180-322-Statement-is-not-valid-or-it-is-used-out-of-proper/m-p/741368#M38801</link>
      <description>&lt;P&gt;Good morning,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381995"&gt;@rotmo86&lt;/a&gt;, and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error messages must be due to something you submitted &lt;EM&gt;before&lt;/EM&gt; the code shown in the screenshot. I see two issues with the macro:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Remember that the DATA step code created by the macro processor is executed only &lt;EM&gt;after&lt;/EM&gt; the macro processor has finished its work. This implies that values of variables read by the DATA step &lt;EM&gt;cannot&lt;/EM&gt; be used by the macro processor. Therefore the &lt;FONT color="#FF0000"&gt;%&lt;/FONT&gt;DO &lt;FONT color="#FF0000"&gt;%&lt;/FONT&gt;WHILE ... &lt;FONT color="#FF0000"&gt;%&lt;/FONT&gt;END loop starting with&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do %while (date&amp;lt;="&amp;amp;end_date"d);&lt;/CODE&gt;&lt;/PRE&gt;
should have remained a DO WHILE loop: It's the &lt;EM&gt;value&lt;/EM&gt; of variable &lt;FONT face="courier new,courier"&gt;date&lt;/FONT&gt; which is to be compared to the &lt;FONT face="courier new,courier"&gt;"&amp;amp;end_date"d&lt;/FONT&gt;&amp;nbsp;(in the DATA step), not the four-letter &lt;EM&gt;text &lt;FONT face="courier new,courier"&gt;date&lt;/FONT&gt;&lt;/EM&gt;&amp;nbsp;(which the macro processor sees).&lt;/LI&gt;
&lt;LI&gt;When macro parameter &lt;FONT face="courier new,courier"&gt;&amp;amp;mylib&lt;/FONT&gt; resolves to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;BaseDeDades_&lt;/FONT&gt;, the DATA step will interpret this as a variable name. So, either use quotes around &lt;FONT face="courier new,courier"&gt;BaseDeDades_&lt;/FONT&gt;&amp;nbsp;in the macro call (as you did in the %LET statement in line 3) or add double quotes in the macro:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_var= "&amp;amp;mylib" ||  put(date,YYMMN6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;These corrections should resolve the issues. Start a new SAS session if leftovers from a previous failed macro call continue to produce errors in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 May 2021 09:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/ERROR-180-322-Statement-is-not-valid-or-it-is-used-out-of-proper/m-p/741368#M38801</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-05-14T09:35:54Z</dc:date>
    </item>
  </channel>
</rss>

