Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mf_getschema.sas
Go to the documentation of this file.
1 /**
2  @file mf_getschema.sas
3  @brief Returns the database schema of a SAS library
4  @details Usage:
5 
6  %put %mf_getschema(MYDB);
7 
8  returns:
9  > dbo
10 
11  @param libref Library reference (also accepts a 2 level libds ref).
12 
13  @return output returns the library schema for the FIRST library encountered
14 
15  @warning will only return the FIRST library schema - for concatenated
16  libraries, with different schemas, inconsistent results may be encountered.
17 
18  @version 9.2
19  @author Allan Bowe
20 **/
21 
22 %macro mf_getschema(libref
23 )/*/STORE SOURCE*/;
24  %local dsid vnum rc schema;
25  /* in case the parameter is a libref.tablename, pull off just the libref */
26  %let libref = %upcase(%scan(&libref, 1, %str(.)));
27  %let dsid=%sysfunc(open(sashelp.vlibnam(where=(
28  libname="%upcase(&libref)" and sysname='Schema/Owner'
29  )),i));
30  %if (&dsid ^= 0) %then %do;
31  %let vnum=%sysfunc(varnum(&dsid,SYSVALUE));
32  %let rc=%sysfunc(fetch(&dsid));
33  %let schema=%sysfunc(getvarc(&dsid,&vnum));
34  %put &libref. schema is &schema.;
35  %let rc= %sysfunc(close(&dsid));
36  %end;
37 
38  &schema
39 
40 %mend;