Hola ,Estoy en busca de como realizar una consulta de una tabla con base en una macro que proviene de otra tabla , esto Ya lo he logrado , sin embargo quiero que esta se repita N# de Veces Teniendo encuenta que al termino de una consulta se sume N =N+1 y vuelva a comenzar una parte del programa desde que comienza el Do hasta End Gracias
Data;
%LET N=0;
%LET O=1;
%LET N=%eval(&N+&O);
do while(&n < 5);
PROC SQL;
SELECT
PUT(CTA_CVE,19.) INTO:CLIENTE
From WORK.CTA_MES_L Where ROW_NUM =&N
;QUIT;
%PUT &CLIENTE;
PROC SQL;
SELECT
(CTA_FCH_PRM_CMP) INTO:FCH_PRM_CMP
From WORK.CTA_MES_L Where ROW_NUM =&N
;QUIT;
%PUT &FCH_PRM_CMP;
PROC SQL;
Create table TXN as
Select
FCH Format DATE9. Length 8,
INF Format 6. Length 8,
CVE Format 19. Length 8,
TRN_CVE Format 6. Length 8,
PLAN_CVE Format 11. Length 8,
TRN_IMP Format 20.2 Length 8
From TABLE.VFAC_TR
where FCH_FCH = "&FCH_PRM_CMP"D
And CTA_CVE=&CLIENTE;
QUIT;
PROC SQL; /* */
INSERT INTO NFCONTRO.ACUM
SELECT * FROM TXN ;
RUN;
%end;
proc sql;
create table txn as select
put(a.cta_cve,19.) as cliente,
a.cta_fch_prm_cmp as fch_prm_cmp,
b.fch,
b.inf,
b.cve
/* More variables can go here if you want */
from cta_mes_l as a left join vfac_t as b
on b.fch_fch=a.fch_prm_cmp
and b.cta_cve=put(a.cta_cve,19.);
quit;
This is completely untested because I don't have your data sets, and so there may be some modifications needed, but this will do what you want without looping and without macros.
From now on, when you think about using macros and loops, stop and ask yourself (and ask others in this forum or other who you work with) if macros are need and if loops are needed. Macros are incredibly inefficient here, and take a lot longer to program properly.
Please explain (in words, not in SAS code) what this sequence of SQL with macro variables is trying to do. It seems as if you are extracting one row from a data set in one SQL to get a date value, then extracting the same row from another data set in the next SQL to get a client, and then doing a third operation where you extract data from another data set by date and client.
None of this requires a macro, none of this requires a loop, if I am understanding your code, however I am guessing. Please take the time to explain what it is doing.
None of this requires a loop or a macro.
Extract from each database all 70000 desired records into a data set. Using PROC SQL, join the two data base extracts and the data in VFAC_TR.
proc sql;
create table txn as select
put(a.cta_cve,19.) as cliente,
a.cta_fch_prm_cmp as fch_prm_cmp,
b.fch,
b.inf,
b.cve
/* More variables can go here if you want */
from cta_mes_l as a left join vfac_t as b
on b.fch_fch=a.fch_prm_cmp
and b.cta_cve=put(a.cta_cve,19.);
quit;
This is completely untested because I don't have your data sets, and so there may be some modifications needed, but this will do what you want without looping and without macros.
From now on, when you think about using macros and loops, stop and ask yourself (and ask others in this forum or other who you work with) if macros are need and if loops are needed. Macros are incredibly inefficient here, and take a lot longer to program properly.
Saludos estimado, si resolviste tu problema de los ciclos? Yo tengo algunos ejemplos que realizamos para cuando generamos información retroactiva por años y requerimos información por meses, igual podría servirte, quedo a la orden 😉
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!