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.
Wichtiger Haftungsausschluss
Die auf WeAreCAS.eu bereitgestellten Codes und Beispiele dienen Lehrzwecken. Es ist zwingend erforderlich, sie nicht blind in Ihre Produktionsumgebungen zu kopieren. Der beste Ansatz besteht darin, die Logik zu verstehen, bevor sie angewendet wird. Wir empfehlen dringend, diese Skripte in einer Testumgebung (Sandbox/Dev) zu testen. WeAreCAS übernimmt keine Verantwortung für mögliche Auswirkungen oder Datenverluste auf Ihren Systemen.
SAS und alle anderen Produkt- oder Dienstleistungsnamen von SAS Institute Inc. sind eingetragene Marken oder Marken von SAS Institute Inc. in den USA und anderen Ländern. ® zeigt die Registrierung in den USA an. WeAreCAS ist eine unabhängige Community-Site und nicht mit SAS Institute Inc. verbunden.
Diese Website verwendet technische und analytische Cookies, um Ihre Erfahrung zu verbessern.
Mehr erfahren.