Previous Page | Next Page

Examples: Using Metadata Language Elements

Example: Creating a Report with the DATA Step

This example creates an HTML report about servers that are defined in the repository.

%macro server_report (metaserver=myserver,
                      metaport=8561,
                      usr=sasadm@saspw,
                      pw=Password1,
                      includeopt=N,
                      htmlloc=c:\reports\myservers.htm
                      );

options metaserver="&metaserver"
        metarepository="Foundation"
        metaport=&metaport
        metauser="&usr"
        metapass="&pw";

data _null_;
   length ver $20;
   ver=left(put(metadata_version(),8.));
   put ver=;
   call symput('METAVER',ver);
run;

%if %eval(&metaver>0) %then 
   %do;   /* connected to metadata server */
   
      data
      server_connections(keep=id name vendor productname softwareversion hostname 
                         port con_name app_pro com_pro authdomain)
      server_options (keep=name server_opts)
      ;
         length mac_uri dom_uri con_uri urivar uri $500
         id  $17 name vendor productname $50 softwareversion $10 port $4
         authdomain authdesc hostname con_name $40 
         app_pro com_pro propname $20 pvalue pdesc $200 server_opts $500 
         assn attr value $200;
         nobj=1;
         n=1;
         
         nobj=metadata_getnobj("omsobj:ServerComponent?@Id contains '.'",n,uri);
         do i=1 to nobj;
            nobj=metadata_getnobj("omsobj:ServerComponent?@Id contains '.'",i,uri);
            put name=;   
            put '-----------------------------------';
            
            rc=metadata_getattr(uri,"Name",Name);
            rc=metadata_getattr(uri,"id",id);
            rc=metadata_getattr(uri,"vendor",vendor);
            rc=metadata_getattr(uri,"productname",productname);
            rc=metadata_getattr(uri,"softwareversion",softwareversion); 
            
            hostname=' ';
            
            nummac=metadata_getnasn(uri,
                                    "AssociatedMachine",
                                    1,
                                    mac_uri);
            if nummac then
               do;
                  rc=metadata_getattr(mac_uri,"name",hostname);
            end;
            
            numcon=metadata_getnasn(uri,
                                    "SourceConnections",
                                    1,
                                    con_uri);
            
            port=' ';
            con_name=' ';
            app_pro=' ';
            com_pro=' ';
            
            if numcon>0 then
               do;  /* server with connections */
                  do k=1 to numcon;
                     numcon=metadata_getnasn(uri,
                                             "SourceConnections",
                                             k,
                                             con_uri);
                     /* Walk through all the notes on this machine object. */
                     rc=metadata_getattr(con_uri,"port",port); 
                     rc=metadata_getattr(con_uri,"hostname",hostname);
                     rc=metadata_getattr(con_uri,"name",con_name);
                     rc=metadata_getattr(con_uri,"applicationprotocol",app_pro);
                     rc=metadata_getattr(con_uri,"communicationprotocol",com_pro); 
                     
                     numdom=metadata_getnasn(con_uri,
                                             "Domain",
                                             1,
                                             dom_uri);
                    put numdom=;
                    if numdom >=1 then
                       do;
                          rc=metadata_getattr(dom_uri,"name",authdomain);
                          rc=metadata_getattr(dom_uri,"desc",authdesc);
                       end;
                    else authdomain='none';
                       put authdomain=;
                       output server_connections; 
                  end;
               
               end;
            
            else
               do;
                  put 'Server with no connections=' name;   
                  if hostname ne ' ' then 
                     output server_connections;
               end;
            
            server_opts='none';
            numprop=metadata_getnasn(uri,
                                     "Properties",
                                     1,
                                     con_uri);
            do x=1 to numprop;
               numcon=metadata_getnasn(uri,
                                       "Properties",
                                       x,
                                       con_uri);
               /* Walk through all the notes on this machine object. */
               rc=metadata_getattr(con_uri,"propertyname",propname); 
               rc=metadata_getattr(con_uri,"name",pdesc);
               rc=metadata_getattr(con_uri,"defaultvalue",pvalue);
               server_opts=cat(trim(pdesc),' : ',trim(pvalue));
               
               output server_options;
               
            end;
         
         end;
      
      run;
      
      proc sort data=server_connections;
         by name;
      run;
      
      proc sort data=server_options;
         by name;
      run;
      
      proc transpose data=server_options out=sopts prefix=opt;
         by name ;
         var server_opts;
      run;
      
      %if &includeopt=Y %then
         %do; /* include server options on the report */
            data server_report;
               length server_opts $70.;
               merge server_connections server_options;
               by name;
            run;
         %end; /* include server options on the report */
      
      %else 
         %do;
            data server_report;
               length server_opts $1.;
               set server_connections;
            run;
         %end;
         
         ods listing close;
         ods html body="&htmlloc";
            title "Report for Metadata Server &metaserver:&metaport, &sysdate9"; 
            footnote ;
         
         proc report data=server_report 
              nowindows headline headskip split='*' nocenter;
            column name vendor productname softwareversion hostname port
                   con_name app_pro com_pro authdomain 
                   %if &includeopt=Y %then
                      %do; /* include server options on the report */
                         server_opts
                      %end; /* include server options on the report */
                   ; 
            define name            / group flow missing "Server*Name";   
            define vendor          / group flow missing "Vendor";
            define productname     / group flow missing "Product";
            define softwareversion / group missing "Version";
            define port            / group missing "Port";
            define hostname        / group missing "Host Name";
            define con_name        / group missing "Connection*Name";
            define authdomain      / group missing "Authentication*Domain";
            define app_pro         / group missing "App*Protocol";
            define com_pro         / group missing "Com*Protocol";
            
            %if &includeopt=Y %then
               %do; /* include server options on the report */
                  define server_opts / group missing "Server Options";
               %end; /* include server options on the report */
            
            break after name  /  style=[BACKGROUND=CCC];
            
            %if &includeopt=Y %then
               %do; /* include server options on the report */
                  compute after name ;
                  line ' ';
                  line server_opts $70.;
                  line ' ';
                  endcomp;
               %end; /* include server options on the report */
         
         run;
         
         ods html close;
         ods listing;
         
   %end;  /* connected to metadata server */

%else
   %do;   /* could not connect to metadata server */
      %put ERROR: could not connect to &metaserver &metaport. ;
      %put ERROR: check connection details, userid and password.;
   %end; /* could not connect to metadata server */

%mend;

%server_report (metaserver=myserver,
                metaport=8561,
                usr=sasadm@saspw,
                pw=Password1,
                includeopt=N,
                htmlloc=c:\reports\myservers.htm
                );
 

Here is the HTML report:

[untitled graphic]

Previous Page | Next Page | Top of Page