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.);
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
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.
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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.