Hello! Firstly, I believe you are confusing the scan function (which receives only text values) with the % scan macro macro. Whenever you have the symbol "% " before the function name, it is a macro function, which takes a variable macro as an argument. In this way, the % scan macro function can also be used with numeric values.
I believe the warning that appeared was something like "WARNING: Macro variable LIM_MSISDN is not initialized" . This happened because you forgot to put the ampersand (symbol & ") before the text NR, indicating that NR is a variable macro, in this section here: % LET LIM_MSISDN =% EVAL (NR) . you do not need to use % eval here, you only use % eval when you are going to do some arithmetic operation with variable macro value, which is not the case here; here you just want to copy the value.
I've put down two code suggestions that should work for what you want to do:
Code 1: I'm not sure if it works because I've never used '*' to separate elements into macro variables and I do not have SAS here to test:
proc sql;
select ID INTO: LISTA_ID SEPARATED BY '*' from
WORK.AMOSTRA;
quit;
%MACRO CICLO_teste;
%let num_elementos = %sysfunc(countw(&LISTA_ID.), %str(*));
%do i = 1 %to &num_elementos.;
%let ref = %scan(&LISTA_ID., &i., *);
DATA WORK.UP&REF;
SET WORK.BASE&REF;
FORMAT PERC_ACUM 9.3;
IF FIRST.ID_CLIENTE THEN PERC_ACUM=0;
PERC_ACUM+PERC;
RUN;
%end;
%MEND CICLO_TESTE;
%CICLO_TESTE;
Code 2: Using space to separate variable macro elements:
proc sql;
select ID INTO: LISTA_ID SEPARATED BY ' ' from
WORK.AMOSTRA;
quit;
%MACRO CICLO_teste;
%let num_elementos = %sysfunc(countw(&LISTA_ID.));
%do i = 1 %to &num_elementos.;
%let ref = %scan(&LISTA_ID., &i.,' ');/*Como usei espaço como separador, nem precisava colocar o terceiro argumento, mas deixei aqui pra ficar explícito*/
DATA WORK.UP&REF;
SET WORK.BASE&REF;
FORMAT PERC_ACUM 9.3;
IF FIRST.ID_CLIENTE THEN PERC_ACUM=0;
PERC_ACUM+PERC;
RUN;
%end;
%MEND CICLO_TESTE;
%CICLO_TESTE;