Hi,
i recive this error:
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &N = 1 AND &MESE_PARTENZA <> -12
ERROR: The macro LOOPMONTH will stop executing.
from this macro:
%LET DT_START='30APR2018'D;
%LET PERIDO=12;
%LET TERM_YM =201804;
%LET YM = 052018;
%let STRANA = TGSTRANA;
%let TGERCOM = tggercom;
/*LDS*/
%LET DT_START_LDS='30APR2018'D;
%LET PERIDO_LDS=12;
%LET PERIDO_LDS_PRE = 3;
%macro loopMonth (PERIDO_LDS_PRE, NAME, MESE_PARTENZA );
%let N =1;
%do %UNTIL( &N = &PERIDO_LDS_PRE + 1) ;
%if &N = 1 AND &MESE_PARTENZA = -12 %then %LET DT_MONTH_LDS = &DT_START_LDS;
%if &N = 1 AND &MESE_PARTENZA <> -12 %then %LET DT_MONTH_LDS = intnx('month',&DT_MONTH_LDS, &MESE_PARTENZA);
%if &N > 1 %then %LET DT_MONTH_LDS = intnx('month',&DT_MONTH_LDS, -1);
data _null_;
call symput('YEAR', YEAR(&DT_MONTH_LDS) );
call symput('MONTH', month(&DT_MONTH_LDS));
run;
data _null_;
call symput('YEARMONTH',cats( put(&YEAR.,z4.),put(&MONTH.,z2.)));
call symput('YEARMONTH_M',cats( substr( PUT(&YEAR.,Z4.), length(PUT(&YEAR.,Z4.)) - 1,2), put(&MONTH.,z2.), 'ATMWEB.mdb' ) ); /* mdb accdb */
call symput('YEARMONTH_M2',cats( substr( PUT(&YEAR.,Z4.), length(PUT(&YEAR.,Z4.)) - 1,2), put(&MONTH.,z2.) ) );
call symput('MONTH', put(&MONTH.,z2.));
call symput('MOLOGATM',cats('MOLOGATM', put(&YEAR.,z4.),put(&MONTH.,z2.)));
run;
%put NOTE: &N;
PROC SQL;
CREATE TABLE WORK.&NAME&&N AS
SELECT &YEARMONTH AS YEARMONTH,
C.keyatm,
/* TOLGO I VALORI ZERO PER NON FALSARE LA MEDIA */
(CASE
WHEN C.LdS_prelievo = 0 THEN .
ELSE ROUND(C.LdS_prelievo/100,0.0001)
END) as LDS_PREL LABEL='LDS_PREL',
(CASE
WHEN C.Lds_Vers_Assegni = 0 THEN .
ELSE ROUND(C.Lds_Vers_Assegni/100,0.0001)
END) AS LDS_VER_AS LABEL='LDS_VER_AS',
(CASE
WHEN C.LdS_Vers_Contanti = 0 THEN .
ELSE ROUND(C.LdS_Vers_Contanti/100,0.0001)
END) AS LDS_VER_CO LABEL='LDS_VER_CO'
,
c.Carico_filiale,
c.Carico_problemi_linee,
c.Carico_assistenza,
c.Carico_varie_e_inceppamenti,
c.Carico_vigilanza
FROM LDS.Tcol54_&YEARMONTH_M2 c
;
quit;
%let N=%eval(&N +1);
%end;
%mend loopMonth;
%loopMonth (&PERIDO_LDS_PRE, Z_PRE_A_ , -12 );
Can someone give me advice on how to solve?
thank's so much
Hi,
The use of <> as an operator in the %if statement is not valid. You can for example use ne instead.
See the section on Operands and Operators in:
You might find you have other issues, for example consider using %eval for integer arithmetic in the %do %until loop control, for starters.
Regards,
Amir.
Edit: Corrected "operand" to be "operator".
Hi,
The use of <> as an operator in the %if statement is not valid. You can for example use ne instead.
See the section on Operands and Operators in:
You might find you have other issues, for example consider using %eval for integer arithmetic in the %do %until loop control, for starters.
Regards,
Amir.
Edit: Corrected "operand" to be "operator".
What is it your trying to do? Macro is not the place to be doing data processing, and from the looks of it your breaking data up into smaller bits and putting data into dataset names:
CREATE TABLE WORK.&NAME&&N AS
It is rarely a good idea to split like data into blocks, this will just increase storage needs, make your code slower, and you will have to write a lot more messy code. SAS has built in, and very powerful by group processing to handle these types of things. In you main dataset, just add another variable which is the grouping - what you would put in the &name&&n - then use this as by <thevariable>; Far simpler, quicker, less storage etc. and just better all round.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.