Retrieve the list of names: Use dictionary views (SASHELP.VTABLE) to automatically list everything in a library.
Generate the code dynamically: Use the CALL EXECUTE statement in a Data Step to run the macro for each name found.
2. The Code Step by Step
Step 0: Define the Processing Macro
This is the code the user wants to execute for a single table.
%macro jig(name);
data datdir.NEW_&name;
/* Attention : les deux tables doivent être triées par ID au préalable */
merge excelsheetdata datdir.&name;
by ID;
run;
%mend jig;
1
%macro jig(name);
2
DATA datdir.NEW_&name;
3
/* Attention : les deux tables doivent être triées par ID au préalable */
proc sql;
create table liste_tables as
select memname
from sashelp.vtable
where libname='DATDIR' /* Nom de la lib en MAJUSCULES */
and memname like 'DATA_%'; /* Filtre optionnel si besoin */
quit;
1
PROC SQL;
2
create TABLE liste_tables as
3
select memname
4
from sashelp.vtable
5
where LIBNAME='DATDIR'/* Nom de la lib en MAJUSCULES */
6
and memname like 'DATA_%'; /* Filtre optionnel si besoin */
7
QUIT;
Note: SASHELP.VTABLE contains the metadata for all active tables.
Note : Step 2: Automation (CALL EXECUTE)
This is where the magic happens. We loop through the list created in Step 1, and for each row, we build a text command that calls the macro.
data _null_;
set liste_tables;
/* Construction de la chaîne : '%jig(TABLE_1)' */
commande = '%jig(' || strip(memname) || ')';
/* Exécution immédiate de cette commande */
call execute(commande);
run;
1
DATA _null_;
2
SET liste_tables;
3
4
/* Construction de la chaîne : '%jig(TABLE_1)' */
5
commande = '%jig(' || strip(memname) || ')';
6
7
/* Exécution immédiate de cette commande */
8
call execute(commande);
9
RUN;
3. Syntax Analysis of CALL EXECUTE
In the solution proposed by WeAreCas, you will notice a somewhat complex syntax:
Technical advice: Don't forget that for a MERGE to work, all your tables (all 50 of them!) must be previously sorted by the key variable (ID). If this is not the case, you will need to add a PROC SORT inside your %jig macro.
Aviso importante
Los códigos y ejemplos proporcionados en WeAreCAS.eu son con fines educativos. Es imperativo no copiarlos y pegarlos ciegamente en sus entornos de producción. El mejor enfoque es comprender la lógica antes de aplicarla. Recomendamos encarecidamente probar estos scripts en un entorno de prueba (Sandbox/Dev). WeAreCAS no acepta ninguna responsabilidad por cualquier impacto o pérdida de datos en sus sistemas.
SAS y todos los demás nombres de productos o servicios de SAS Institute Inc. son marcas registradas o marcas comerciales de SAS Institute Inc. en los EE. UU. y otros países. ® indica registro en los EE. UU. WeAreCAS es un sitio comunitario independiente y no está afiliado a SAS Institute Inc.
Este sitio utiliza cookies técnicas y analíticas para mejorar su experiencia.
Saber más.