Macros for SAS Application Developers
https://github.com/sasjs/core
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 %let dsid=%sysfunc(open(sashelp.vlibnam(where=(
29 libname="%upcase(&libref)" and sysname='Schema/Owner'
30 )),i));
31 %if (&dsid ^= 0) %then %do;
32 %let vnum=%sysfunc(varnum(&dsid,SYSVALUE));
33 %let rc=%sysfunc(fetch(&dsid));
34 %let schema=%sysfunc(getvarc(&dsid,&vnum));
35 %put &libref. schema is &schema.;
36 %let rc= %sysfunc(close(&dsid));
37 %end;
38
39 &schema
40
41%mend mf_getschema;
42
43/** @endcond */