Loading...
Searching...
No Matches
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 [in] 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 @cond
21**/
22
23%macro mf_getschema(libref
24)/*/STORE SOURCE*/;
25 %local dsid vnum rc schema;
26 /* in case the parameter is a libref.tablename, pull off just the libref */
27 %let libref = %upcase(%scan(&libref, 1, %str(.)));
28 /* sysname can be 'Schema/Owner' or just 'Schema' (eg snowflake) */
29 %let dsid=%sysfunc(open(sashelp.vlibnam(where=(
30 libname="%upcase(&libref)" and sysname=:'Schema'
31 )),i));
32 %if (&dsid ^= 0) %then %do;
33 %let vnum=%sysfunc(varnum(&dsid,SYSVALUE));
34 %let rc=%sysfunc(fetch(&dsid));
35 %let schema=%sysfunc(getvarc(&dsid,&vnum));
36 %put &libref. schema is &schema.;
37 %let rc= %sysfunc(close(&dsid));
38 %end;
39
40 &schema
41
42%mend mf_getschema;
43
44/** @endcond */