BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
carles
Fluorite | Level 6

Dear everyone, 

 

Thank you in advanced for your time. 

 

Why do I get the mistake in the code ? Outside the macro it works.

 

fecha_list = 201812 201901;
%macro AllFechasScore(mes_proceso_list);

	%LOCAL i fecha fecha_1m_anterior fecha_2m_anterior;
	
	%let i=1;

	%DO %WHILE (%SCAN(&mes_proceso_list., &i., ' ') ne );
		   %let fecha 	= %SCAN(&mes_proceso_list., &i., ' ');
		   /*Creating fecha_1m_anterior*/
			data _null_;
			  call symput ('fecha_1m_anterior',
			  				1*put(intnx('month',mdy( mod(&fecha.,100),1,int(&fecha./100) ) ,-1),yymmn6.)
						  );
			run;
			/*Creating fecha_2m_anterior*/
			data _null_;
			 	call symput ('fecha_2m_anterior',
			  				1*put(intnx('month',mdy( mod(&fecha_1m_anterior.,100),1,int(&fecha_1m_anterior./100) ) ,-1),yymmn6.)
						  );
			run;

		   /* Printings in log*/
		   	%put num_iter = &i.;
			%put fecha hoy = &fecha.;
			%put fecha 1 mes anterior = &fecha_1m_anterior.;
			%put fecha 2 mes anterior = &fecha_2m_anterior.;

		  
		%end;
		%let i = %eval(&i + 1);

%mend;
%AllFechasScore(&fecha_list.);
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Hi,

First, you need `%LET` before

fecha_list = 201812 201901;

 since it is macro code not datastep code.

 

Second, if you are using `%scan()` avoid `' '`  and use `%STR( )` instead

Third, use `symputX()`

Fourth, the `%let i = %eval(&i + 1);` should be inside the %DO %WHILE loop

Fifth, the `1*put(...` is very strange and unnecessary in my opinion

 

Try this:

%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(&mes_proceso_list., &i., %STR( )) ne );
		   %let fecha 	= %SCAN(&mes_proceso_list., &i., %STR( ));
		   /*Creating fecha_1m_anterior*/
			data _null_;
			  call symputX ('fecha_1m_anterior',
			  				put(intnx('month',mdy( mod(&fecha.,100),1,int(&fecha./100) ) ,-1),yymmn6.)
						  ,'l');
			run;
			/*Creating fecha_2m_anterior*/
			data _null_;
			 	call symputX ('fecha_2m_anterior',
			  				put(intnx('month',mdy( mod(&fecha_1m_anterior.,100),1,int(&fecha_1m_anterior./100) ) ,-1),yymmn6.)
						  ,'l');
			run;

		   /* Printings in log*/
		   	%put num_iter = &i.;
			%put fecha hoy = &fecha.;
			%put fecha 1 mes anterior = &fecha_1m_anterior.;
			%put fecha 2 mes anterior = &fecha_2m_anterior.;

		 %let i = %eval(&i + 1); 
		%END;
		

%mend;

%AllFechasScore(&fecha_list.);

All the best

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

First, place this command as the first line of your program and run it again

 

options symbolgen mlogic mprint;

The next step is critical to help us understand and interpret the results. PLEASE DO NOT SKIP THIS STEP. Click on the </> icon and then copy and paste the LOG (as text) from your run into the window that appears. PLEASE DO NOT SKIP THIS STEP.

--
Paige Miller
yabwon
Onyx | Level 15

Hi,

First, you need `%LET` before

fecha_list = 201812 201901;

 since it is macro code not datastep code.

 

Second, if you are using `%scan()` avoid `' '`  and use `%STR( )` instead

Third, use `symputX()`

Fourth, the `%let i = %eval(&i + 1);` should be inside the %DO %WHILE loop

Fifth, the `1*put(...` is very strange and unnecessary in my opinion

 

Try this:

%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(&mes_proceso_list., &i., %STR( )) ne );
		   %let fecha 	= %SCAN(&mes_proceso_list., &i., %STR( ));
		   /*Creating fecha_1m_anterior*/
			data _null_;
			  call symputX ('fecha_1m_anterior',
			  				put(intnx('month',mdy( mod(&fecha.,100),1,int(&fecha./100) ) ,-1),yymmn6.)
						  ,'l');
			run;
			/*Creating fecha_2m_anterior*/
			data _null_;
			 	call symputX ('fecha_2m_anterior',
			  				put(intnx('month',mdy( mod(&fecha_1m_anterior.,100),1,int(&fecha_1m_anterior./100) ) ,-1),yymmn6.)
						  ,'l');
			run;

		   /* Printings in log*/
		   	%put num_iter = &i.;
			%put fecha hoy = &fecha.;
			%put fecha 1 mes anterior = &fecha_1m_anterior.;
			%put fecha 2 mes anterior = &fecha_2m_anterior.;

		 %let i = %eval(&i + 1); 
		%END;
		

%mend;

%AllFechasScore(&fecha_list.);

All the best

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



carles
Fluorite | Level 6
Thank you Bart, apparently I had too many stupid mistakes like (1), (4) and (5);
I will learn though about (2) and ·(3), which I did not.

Thank you so much! 🙂

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 949 views
  • 1 like
  • 3 in conversation