Extracting extended attributes is a critical step for auditing or migrating complex SAS 9.4 environments, particularly for LASR libraries where vital parameters—such as server ports or startup options—are stored as Name/Value pairs within the metadata. The key to this technique is navigating the "Extensions" association using the metadata_getnasn function to drill down into the SASLibrary object. As a best practice, always initialize your variables and check the return code (rc) of metadata_getattr to ensure the attribute exists, preventing residual values from the Program Data Vector (PDV) from corrupting your output table.
Type : CREATION_INTERNE
Data is dynamically generated by querying the Metadata Server via SAS functions, without reading flat files or external tables.
| 1 | %let LIBNAME='Visual Analytics LASR'; |
| 2 | |
| 3 | options |
| 4 | metaserver="my.sas.server" |
| 5 | metaport=8561 |
| 6 | metauser="sasadm @saspw" |
| 7 | metapass="password" |
| 8 | metarepository=Foundation |
| 9 | metaprotocol=bridge; |
| 1 | DATA extend; |
| 2 | LENGTH type id lib_uri ext_uri ext_name $ 50 ext_val $ 256; |
| 3 | call missing(of _CHARACTER_); |
| 4 | |
| 5 | obj="omsobj:SASLibrary? @Name=&libname"; |
| 6 | |
| 7 | libcount=metadata_resolve(obj,type,id); |
| 8 | IF libcount > 0 THEN DO n=1 to libcount; |
| 9 | rc=metadata_getnobj(obj,n,lib_uri); |
| 10 | ext_count=metadata_getnasn(lib_uri,"Extensions",1,ext_uri); |
| 11 | |
| 12 | IF ext_count > 0 THEN DO m=1 to ext_count; |
| 13 | rc=metadata_getnasn(lib_uri,"Extensions",m,ext_uri); |
| 14 | rc=metadata_getattr(ext_uri,"Name",ext_name); |
| 15 | rc=metadata_getattr(ext_uri,"Value",ext_val); |
| 16 | OUTPUT; |
| 17 | END; ELSE put "NOTE: No Extended Attributes found for library &libname"; |
| 18 | END; |
| 19 | ELSE put "NOTE: No library &libname found."; |
| 20 | |
| 21 | keep ext_name ext_val; |
| 22 | RUN; |