Type : CREATION_INTERNE
La macro ne manipule pas de données tabulaires directement. Elle interroge le serveur de métadonnées SAS pour récupérer des informations de configuration (le nom de la librairie). Le but est de préparer l'accès aux données, dont la source dépendra de la définition de la librairie dans les métadonnées.
| 1 | %macro assign_metalib(libref=/* libref that needs to be assigned */ |
| 2 | ); |
| 3 | %IF %sysfunc(libref(&libref)) %THEN %DO; |
| 4 | DATA _null_; |
| 5 | LENGTH lib_uri LIBNAME $200; |
| 6 | call missing(of _all_); |
| 7 | nobj=metadata_getnobj("omsobj:SASLibrary? @Libref='&libref'",1,lib_uri); |
| 8 | IF nobj=1 THEN DO; |
| 9 | rc=metadata_getattr(lib_uri,"Name",LIBNAME); |
| 10 | call symputx('libname',LIBNAME,'L'); |
| 11 | END; |
| 12 | ELSE IF nobj>1 THEN putlog "ERROR: More than one library with libref='&libref'"; |
| 13 | ELSE putlog "ERROR: Library '&libref' not found in metadata"; |
| 14 | RUN; |
| 15 | |
| 16 | LIBNAME &libref meta library="&libname"; |
| 17 | %IF %sysfunc(libref(&libref)) %THEN |
| 18 | %put ERROR: assign_metalib macro could not assign &libref; |
| 19 | %END; |
| 20 | %ELSE %put NOTE: Library &libref is already assigned; |
| 21 | %mend; |