<?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 49 problem. Code working outside macro but not inside in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646143#M193246</link>
    <description>&lt;P&gt;Dear everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advanced for your time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do I get the mistake in the code ? Outside the macro it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;fecha_list = 201812 201901;
%macro AllFechasScore(mes_proceso_list);

	%LOCAL i fecha fecha_1m_anterior fecha_2m_anterior;
	
	%let i=1;

	%DO %WHILE (%SCAN(&amp;amp;mes_proceso_list., &amp;amp;i., ' ') ne );
		   %let fecha 	= %SCAN(&amp;amp;mes_proceso_list., &amp;amp;i., ' ');
		   /*Creating fecha_1m_anterior*/
			data _null_;
			  call symput ('fecha_1m_anterior',
			  				1*put(intnx('month',mdy( mod(&amp;amp;fecha.,100),1,int(&amp;amp;fecha./100) ) ,-1),yymmn6.)
						  );
			run;
			/*Creating fecha_2m_anterior*/
			data _null_;
			 	call symput ('fecha_2m_anterior',
			  				1*put(intnx('month',mdy( mod(&amp;amp;fecha_1m_anterior.,100),1,int(&amp;amp;fecha_1m_anterior./100) ) ,-1),yymmn6.)
						  );
			run;

		   /* Printings in log*/
		   	%put num_iter = &amp;amp;i.;
			%put fecha hoy = &amp;amp;fecha.;
			%put fecha 1 mes anterior = &amp;amp;fecha_1m_anterior.;
			%put fecha 2 mes anterior = &amp;amp;fecha_2m_anterior.;

		  
		%end;
		%let i = %eval(&amp;amp;i + 1);

%mend;
%AllFechasScore(&amp;amp;fecha_list.);&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 May 2020 10:01:25 GMT</pubDate>
    <dc:creator>carles</dc:creator>
    <dc:date>2020-05-08T10:01:25Z</dc:date>
    <item>
      <title>49 problem. Code working outside macro but not inside</title>
      <link>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646143#M193246</link>
      <description>&lt;P&gt;Dear everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advanced for your time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do I get the mistake in the code ? Outside the macro it works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;fecha_list = 201812 201901;
%macro AllFechasScore(mes_proceso_list);

	%LOCAL i fecha fecha_1m_anterior fecha_2m_anterior;
	
	%let i=1;

	%DO %WHILE (%SCAN(&amp;amp;mes_proceso_list., &amp;amp;i., ' ') ne );
		   %let fecha 	= %SCAN(&amp;amp;mes_proceso_list., &amp;amp;i., ' ');
		   /*Creating fecha_1m_anterior*/
			data _null_;
			  call symput ('fecha_1m_anterior',
			  				1*put(intnx('month',mdy( mod(&amp;amp;fecha.,100),1,int(&amp;amp;fecha./100) ) ,-1),yymmn6.)
						  );
			run;
			/*Creating fecha_2m_anterior*/
			data _null_;
			 	call symput ('fecha_2m_anterior',
			  				1*put(intnx('month',mdy( mod(&amp;amp;fecha_1m_anterior.,100),1,int(&amp;amp;fecha_1m_anterior./100) ) ,-1),yymmn6.)
						  );
			run;

		   /* Printings in log*/
		   	%put num_iter = &amp;amp;i.;
			%put fecha hoy = &amp;amp;fecha.;
			%put fecha 1 mes anterior = &amp;amp;fecha_1m_anterior.;
			%put fecha 2 mes anterior = &amp;amp;fecha_2m_anterior.;

		  
		%end;
		%let i = %eval(&amp;amp;i + 1);

%mend;
%AllFechasScore(&amp;amp;fecha_list.);&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 May 2020 10:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646143#M193246</guid>
      <dc:creator>carles</dc:creator>
      <dc:date>2020-05-08T10:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: 49 problem. Code working outside macro but not inside</title>
      <link>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646148#M193249</link>
      <description>&lt;P&gt;First, place this command as the first line of your program and run it again&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mlogic mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The next step is critical to help us understand and interpret the results. PLEASE DO NOT SKIP THIS STEP. Click on the &amp;lt;/&amp;gt; icon and then copy and paste the LOG (as text) from your run into the window that appears.&amp;nbsp;PLEASE DO NOT SKIP THIS STEP.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 10:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646148#M193249</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-08T10:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: 49 problem. Code working outside macro but not inside</title>
      <link>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646149#M193250</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;First, you need `%LET` before&lt;/P&gt;
&lt;PRE&gt;fecha_list = 201812 201901;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;since it is macro code not datastep code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, if you are using `%scan()` avoid `' '`&amp;nbsp; and use `%STR( )` instead&lt;/P&gt;
&lt;P&gt;Third, use `symputX()`&lt;/P&gt;
&lt;P&gt;Fourth, the `%let i = %eval(&amp;amp;i + 1);` should be inside the %DO %WHILE loop&lt;/P&gt;
&lt;P&gt;Fifth, the `1*put(...` is very strange and unnecessary in my opinion&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fecha_list = 201812 201901;
%macro AllFechasScore(mes_proceso_list);

	%LOCAL i fecha fecha_1m_anterior fecha_2m_anterior;
	
	%let i=1;

	%DO %WHILE (%SCAN(&amp;amp;mes_proceso_list., &amp;amp;i., %STR( )) ne );
		   %let fecha 	= %SCAN(&amp;amp;mes_proceso_list., &amp;amp;i., %STR( ));
		   /*Creating fecha_1m_anterior*/
			data _null_;
			  call symputX ('fecha_1m_anterior',
			  				put(intnx('month',mdy( mod(&amp;amp;fecha.,100),1,int(&amp;amp;fecha./100) ) ,-1),yymmn6.)
						  ,'l');
			run;
			/*Creating fecha_2m_anterior*/
			data _null_;
			 	call symputX ('fecha_2m_anterior',
			  				put(intnx('month',mdy( mod(&amp;amp;fecha_1m_anterior.,100),1,int(&amp;amp;fecha_1m_anterior./100) ) ,-1),yymmn6.)
						  ,'l');
			run;

		   /* Printings in log*/
		   	%put num_iter = &amp;amp;i.;
			%put fecha hoy = &amp;amp;fecha.;
			%put fecha 1 mes anterior = &amp;amp;fecha_1m_anterior.;
			%put fecha 2 mes anterior = &amp;amp;fecha_2m_anterior.;

		 %let i = %eval(&amp;amp;i + 1); 
		%END;
		

%mend;

%AllFechasScore(&amp;amp;fecha_list.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 10:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646149#M193250</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-08T10:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: 49 problem. Code working outside macro but not inside</title>
      <link>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646153#M193251</link>
      <description>Thank you Bart, apparently I had too many stupid mistakes like (1), (4) and (5);&lt;BR /&gt;I will learn though about (2) and ·(3), which I did not. &lt;BR /&gt;&lt;BR /&gt;Thank you so much! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 08 May 2020 10:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/49-problem-Code-working-outside-macro-but-not-inside/m-p/646153#M193251</guid>
      <dc:creator>carles</dc:creator>
      <dc:date>2020-05-08T10:44:26Z</dc:date>
    </item>
  </channel>
</rss>

