In a SAS 9.4 environment, the relationship between a SAS Library and an Application Server (like SASApp or SASSTP) is defined through a metadata association called DeployedComponents. This script is an excellent administrative tool for bulk-assigning libraries to new server contexts, which is often required during server migrations or when horizontal scaling is implemented.
Type : MIXED
The script does not use data in the traditional sense (SAS tables). It reads and modifies objects (metadata) directly on the SAS metadata server. The 'source' data are the definitions of server contexts and SAS libraries stored in the metadata.
| 1 | options |
| 2 | metaserver="my.sas.server" |
| 3 | metaport=8561 |
| 4 | metauser="sasadm @saspw" |
| 5 | metapass="password" |
| 6 | metarepository=Foundation |
| 7 | metaprotocol=Bridge; |
| 1 | DATA _null_; |
| 2 | |
| 3 | /* Initialize variables. */ |
| 4 | |
| 5 | LENGTH type id app_uri lib_uri $ 50; |
| 6 | call missing(of _character_); |
| 7 | |
| 8 | /* Define query for the Application Server Context */ |
| 9 | /* to add to the libraries and search for it. */ |
| 10 | |
| 11 | appobj="omsobj:ServerContext? @Name='SASSTP'"; |
| 12 | app_count=metadata_resolve(appobj,type,id); |
| 13 | |
| 14 | /* If no context matches this query, stop the program with an error. */ |
| 15 | |
| 16 | IF app_count <= 0 THEN DO; |
| 17 | put "ERROR: No application server context found matching query " appobj; |
| 18 | stop; |
| 19 | END; |
| 20 | ELSE DO; |
| 21 | |
| 22 | /* Extract the URI of the context if it exists. */ |
| 23 | |
| 24 | rc=metadata_getnobj(appobj,1,app_uri); |
| 25 | |
| 26 | /* Define the query for the libraries to be updated and search for them. */ |
| 27 | |
| 28 | libobj="omsobj:SASLibrary? @code_sas_json/RFValid.json contains '.'"; |
| 29 | lib_count=metadata_resolve(libobj,type,id); |
| 30 | |
| 31 | /* If no libraries match the query, stop the program with an error. */ |
| 32 | IF lib_count <= 0 THEN DO; |
| 33 | put "ERROR: No libraries found matching query " libobj; |
| 34 | stop; |
| 35 | END; |
| 36 | |
| 37 | /* If libraries are found, for each one append */ |
| 38 | /* the context to its list of associated contexts. */ |
| 39 | |
| 40 | ELSE DO n=1 to lib_count; |
| 41 | rc=metadata_getnobj(libobj,1,lib_uri); |
| 42 | rc=metadata_setassn(lib_uri,"DeployedComponents","Append",app_uri); |
| 43 | END; |
| 44 | END; |
| 45 | RUN; |