Know How:BusinessIntelligence:SAS:Metadaten

Aus Ralph's Wiki
Wechseln zu: Navigation, Suche

Hauptseite > Know How > Business Intelligence > SAS > Allgemein

SAS
Allgemeines GlossarDokumentation
Themen SicherheitInstallationKonfigurationAdministrationTroubleshooting
Links ImportExportMacro
Solutions Risk Dimensionsxxx
Tipps MetadatenMakrosJavaNETJSPDATA StepSQLRegExpHashFormateInformation Maps
Tipps:Reporting WebReportStudioInformation Maps
ODS AllgemeinPROC TEMPLATELinks
Internationalization AllgemeinKonfiguration


Inhaltsverzeichnis

Allgemein

Pfadangaben

Bei Pfadangaben werde in der Regel absolute Pfad angegeben, z.b. c:\WORKSHOP\SBAFT. Änderungen im Pfad bedeuten, das dies an allen betroffenen Stellen nachtgezogen werden.

Eine Möglichkeit ist die Vewendung von Variablen

  • Definition der Variable in de SAS Konfigurationssatei, z. B. SASApp\sasv9_usermods.cfg
-set PROJROOT "C:\WORKSHOP\Kursdaten"
  • Verwendung des Vraiable bei Pfadangaben

!PROJROOT\unterverzeichnis

Metadaten durchsuchen

In SAS 9.2 gibts es im SAS Display Manager das Kommando

metabrowse

MetaInfo von Libraries und Datasets

Liste aller Tabellen einer Library

proc datasets library=tmplib nolist;
	contents data=_all_ out=work.output;
run;

proc print data=output; run;

oder mit PROC SQL

proc sql noprint;
	select 	memname into :TABLIST separated by ' '
	from	sashelp.vtable
	where	libname="TMPLIB" and memname like "TEST%";
quit;

%put &TABLIST;

MetaInfo aus einem Repository

Informationen über ein Dataset

Liste der Variablen eines Dataset

   proc contents data=sashelp.class noprint out=work.metainfo;
   run;

Ergibt dann die Ausgabe in das Dataset work.metainfo mit dne folgenden Inhalt:

Meta Data for SASHELP.CLASS
Obs  NAME   TYPE LENGTH VARNUM
1    Age      1    8       3
2    Height   1    8       4
3    Name     2    8       1
4    Sex      2    1       2
5    Weight   1    8       5

Beispiele

Metadaten auslesen mit Base SAS

Determining the filepath root in Enterprise Guide

%let root = ;
data _null_;
   length obj id navpath $256 type $32;
   call missing(id,type,navpath);
   obj="omsobj:Property?Property[@PropertyName='FileNavigation']AssociatedObject/ServerComponent[@Name contains 'Workspace']UsedbyComponents/LogicalServer/UsedByComponents/ServerContext[@Name='" || "&_SASSERVERNAME." || "']]";

   rc=metadata_resolve(obj,type,id);

   if (rc > 0) then do;
      rc2=metadata_getattr(obj,"DefaultValue",NavPath);
      call symput('Root',trim(NavPath));
    end;
   else put 'ERROR: No Property found ' obj=;
      run;
   %put NOTE: Environment Root is: &root..;

User Management

Check if _METAPERSON is a Member of a particuliar Group

Der originalcode liegt hier [1]

Determine if _MetaPerson is a member of specified group. Can be used in Stored Process, or Standalone SAS session. Standalone Session requires setting the value of _MetaPerson macro variable and the required Metadata system options. Set macro variable groupname to value of group in question.

/* _MetaPerson_isamember_of_group.sas */ 
/*  Find if a user is a member of a particuliar group  */
/*  Code uses Metadata_Resolve data step function to detemine group membership */
/*  Author BT 19SEP2006 */
/* Set Metadata system options if needed  */
/*
options metauser="userid" metapass="pass" metarepository="Foundation" 
        metaserver="serverip"  metaport=8561;
*/

/* uncomment and set _MetaPerson value if needed   */
/* %let _MetaPerson=SAS Demo User; */	/* No need to set this for a Stored Process */

%let groupname=Oragroup;		 /* Name of group to check membership         */
data _null_;
    length obj  type $256 id $20;
	getperson=symget('_metaperson');
	getgroup=symget('groupname');
	type="";
	id="";
   /* Build URI for the group with a name of & groupname, and that a &_MetaPerson is a member  */
   obj="omsobj:IdentityGroup?IdentityGroup[@Name='"||"&groupname"
   ||"'][MemberIdentities/Person[@Name='"||"&_METAPERSON"||"']]";
   *put obj=;
   rc=metadata_resolve(obj,type,id);
   *put rc=;  /*  This should be 1  if person is member of group */
   if (rc) then do;
      *put type= id=;
      call symput('isamember','1');
	  Call symput('Isamemberc','Yes');
      put "Is &_metaperson a member of Group &groupname..?  Yes. "  rc=;
   end;
   else do;
      call symput('isamember','0');
	  Call symput('Isamemberc','No');

      put "&_MetaPerson is a not member of Group &groupname.. "  rc=;
   end;
 
run;

%put "Is &_MetaPerson a member of group &groupname.?" "&Isamemberc";

Makros zu Auslesen der MetaDaten

md_get_rep_id

/*======================================================================*/
/*                                                                      */
/* USAGE: %md_get_rep_id(name);                                         */
/*        %put Repository ID=&md_id;                                    */
/*                                                                      */
/*======================================================================*/
%macro md_get_rep_id(name);
	%global md_id;
	%global md_rc;

	data _null_;
		length id $ 20 type $ 256;

		type = '';
		id   = '';

		rc=metadata_resolve("omsobj:RepositoryBase?@Name='&name.'",type,id);

		call symput('md_id', id);
		call symput('md_rc', rc);
	run;
%mend md_get_rep_id;

md_get_lib_id

/*======================================================================*/
/*                                                                      */
/* USAGE: %md_get_lib_id(sashelp);                                      */
/*        %put Repository ID=&md_id;                                    */
/*                                                                      */
/*======================================================================*/
%macro md_get_lib_id(name);
	%global md_id;
	%global md_rc;

	data _null_;
		length id $ 20 type $ 256;

		type = '';
		id   = '';

		rc=metadata_resolve("omsobj:SASLibrary?@Name='&name.'",type,id);

		call symput('md_id',id);
		call symput('md_rc',rc);
	run;
%mend md_get_lib_id;

md_get_attr

/*======================================================================*/
/*                                                                      */
/* USAGE: %md_get_attr(id, name);                                       */
/*        %put Value=&md_value;                                         */
/*                                                                      */
/*======================================================================*/
%macro md_get_attr(id, name);

	%global md_value;
	%global md_rc;

	data _null_;
		length value $ 256;

		rc=metadata_getattr("omsobj:&id.","&name.",value);

		call symput('md_value', value);
		call symput('md_rc'   , rc);

	run;

%mend md_get_attr;

md_set_attr

/*======================================================================*/
/*                                                                      */
/* USAGE: %md_set_attr(id, name, value);                                */
/*        %put Return Code &md_rc;                                      */
/*                                                                      */
/*======================================================================*/
%macro md_set_attr(id, name, value);

	%global md_rc;

	data _null_;
		rc=metadata_setattr("omsobj:&id.","&name.","&value.");

		call symput('md_rc', rc);
	run;

%mend md_set_attr;

MetaDaten auslesen mit java

Get Information using java

Here is an example from support.sas.com [2]

import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SAS.IWorkspaceHelper;
import com.sas.meta.SASOMI.IOMI;
import com.sas.meta.SASOMI.IOMIHelper;
import com.sas.services.connection.BridgeServer;
import com.sas.services.connection.ConnectionFactoryAdminInterface;
import com.sas.services.connection.ConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.ManualConnectionFactoryConfiguration;
import com.sas.services.connection.omr.OMRConnectionFactoryConfiguration;
import com.sas.services.connection.Server;

String classID = Server.CLSID_SASOMI;
String host = "omr.pc.abc.com";
int port = 8561;

// Set the credentials for the metadata server connection. If connecting to
// a pooled server, these should be the credentials for the pooling
// administrator.
String userName_omr = "Adm1";
String password_omr = "Adm1pass";

// Step 1. Create a connection factory configuration for the metadata server
// and get a connection factory manager.
Server omrServer = new BridgeServer(classID,host,port);
ConnectionFactoryConfiguration cxfConfig_omr =
   new ManualConnectionFactoryConfiguration(omrServer);

ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();

// Step 2. Create a connection factory for the metadata server connection
// factory configuration.
ConnectionFactoryInterface cxf_omr = cxfManager.getFactory(cxfConfig_omr);

// Step 3. Get a connection to the metadata server.
ConnectionInterface cx_omr = cxf_omr.getConnection(userName_omr,password_omr);

// Step 4. Narrow the connection from the metadata server.
org.omg.CORBA.Object obj_omr = cx_omr.getObject();
IOMI iOMI = IOMIHelper.narrow(obj_omr);

String reposID = "A0000001.A1234567";
String name= "login015Logical";

// Step 5. Create a connection factory configuration for the server by passing
// the server logical name to the metadata server.
ConnectionFactoryConfiguration cxfConfig =
   new OMRConnectionFactoryConfiguration(iOMI,reposID,name);

// Step 6: Get a connection factory that matches the server's connection
// factory configuration.
ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);

// Set the credentials for the server connection.
String userName = "citynt\\use1";
String password = "use1pass";
String domain = "citynt";

// Step 7: Get a connection to the server.
ConnectionInterface cx = cxf.getConnection(userName,password,domain);

// Step 8: Narrow the connection from the server.
org.omg.CORBA.Object obj = cx.getObject();
IWorkspace iWorkspace = IWorkspaceHelper.narrow(obj);

< insert iWorkspace workspace usage code here >

// Step 9: Close the workspace connection and shutdown the connection factory.
cx.close();
cxf.shutdown();

// Step 10: Close the metadata server connection and shutdown the connection
// factory.
cx_omr.close();
cxf_omr.shutdown();

Auslesen aller Tabellen, deren Beschreibung sowie erweiterter Attribute

options metaRepository="DEMO";

proc format library=demolib;
   value err_metadata_getnasn
      other = "The number of associated objects"
      -1    = "Unable to connect to the metadata server"
      -3    = "No objects match the given URI"
      -4    = "n is out of range"
   ;

   value err_metadata_getattr
       0    = "Successful completion"
      -1    = "Unable to connect to the metadata server"
      -2    = "The attribute was not found"
      -3    = "No objects matches the URI"
   ;
run;

options fmtsearch=(demolib);

data _null_;
	length	uri1  	$100 
		uri2	$100
		name1 	$256
		name2 	$256
		desc1	$256
		desc2	$256
		value2	$256
		;

	attrib rc1 length=8 format=err_metadata_getnasn.;
	attrib rc2 length=8 format=err_metadata_getnasn.;

	name1=''; name2=''; desc1=''; desc2=''; uri1=''; uri2=''; value2='';
	loop1=1;

	put "Start reading all tables";

	do until (rc1 < 0);
		rc1=metadata_getnasn("omsobj:SASLibrary?@Name='demolib'", "Tables", loop1, uri1);

		if rc1 > 0 then do;
			rcx=metadata_getattr(uri1, "Name", name1);
			rcx=metadata_getattr(uri1, "Desc", desc1);

			put  name1= desc1= uri1=;

			loop2=1;

			do until (rc2 < 0);
				rc2=metadata_getnasn(uri1, "Extensions", loop2, uri2);

				if rc2 > 0 then do;
					rcx=metadata_getattr(uri2, "Name" , name2);
					rcx=metadata_getattr(uri2, "Value", value2);
					rcx=metadata_getattr(uri2, "Desc" , desc2);
		
					put  name1= name2= desc2= uri2=;
				end;

				loop2+1;
			end;
		end;
		
		loop1+1;
	end;
run;
Meine Werkzeuge