METADATA_NEWOBJ Function

Creates a new metadata object.

Syntax

rc = METADATA_NEWOBJ(type, uri<, name><, repos><, parent><, asn>);

Required Arguments

type (in)
specifies a metadata type.
uri (out)
returns a Uniform Resource Identifier (URI).

Optional Arguments

name (in)
specifies a value for the Name attribute of the new metadata object.
repos (in)
specifies the repository identifier of an existing repository. By default, the new object is created in the default repository.
parent (in)
specifies the Uniform Resource Identifier (URI) of an existing metadata object with which to associate the new metadata object. Must be used with ASN. ASN specifies the association name that relates the two metadata objects.
asn (in)
specifies an association name that is relative to the parent metadata object.

Return Values

0
Successful completion.
-1
Unable to connect to the metadata server.
-2
Unable to create object; see the SAS log for details.

Details

When you create a new metadata object, the object might be unusable if you do not create the proper attributes and associations. For more information, see the SAS Metadata Model: Reference.
The following example creates a SASLibrary object, PhysicalTable object, and Column objects, and associates the library with the table. Note that each object has PublicType= and UsageVersion= attributes defined. The SASLibrary and PhysicalTable objects also have a containing folder defined.

Example

options metaserver="myserver"
        metaport=8561
        metauser="sasadm@saspw"
        metapass="adminpw"
        metarepository="Foundation";

data _null_;
    length uri $256
           curi $256
           curi1 $256
           curi2 $256
           luri $256;

    rc=0;

	/* Create a SASLibrary object in the Shared Data folder. */

    rc=metadata_newobj("SASLibrary",
                       luri,
                       "DS Test Library",
						"Foundation",
						"omsobj:Tree?@Name='Shared Data'",
						"Members");
    put rc=;
    put luri=;

	/* Add PublicType= and UsageVersion= attribute values. */

		rc=metadata_setattr(luri, 
							"PublicType",
							"Library");
		put rc=;
		put luri=;

		rc=metadata_setattr(luri, 
							"UsageVersion",
							"1000000.0");
		put rc=;
		put luri=;

   
    /* Create a PhysicalTable object in the Shared Data folder. */

		rc=metadata_newobj("PhysicalTable",
                       uri,
                       "TestTable",
						"Foundation",
						"omsobj:Tree?@Name='Shared Data'",
						"Members");
    put rc=;
    put uri=;

	/* Add PublicType= and UsageVersion= attribute values. */

		rc=metadata_setattr(uri, 
							"PublicType",
							"Table");
		put rc=;

		rc=metadata_setattr(uri, 
							"UsageVersion",
							"1000000.0");
		put rc=;

    /* Create a couple of columns on the new PhysicalTable object. */

  rc=metadata_newobj("Column",
                      curi,
                      "Column1",
                      "Foundation",
                      uri,
                      "Columns");

		put rc=;
		put curi=;

		/* Add PublicType= and UsageVersion= attribute values to Column. */
		rc=metadata_setattr(curi, 
							"PublicType",
							"Column");
		put rc=;

		rc=metadata_setattr(curi, 
							"UsageVersion",
							"1000000.0");
		put rc=;


		rc=metadata_newobj("Column",
                       curi1,
                       "Column2",
                       "Foundation",
                       uri,
                       "Columns");

		put rc=;
		put curi1=;

/* Add PublicType= and UsageVersion= attribute values to Column2. */
		rc=metadata_setattr(curi1, 
							"PublicType",
							"Column");
		put rc=;

		rc=metadata_setattr(curi1, 
							"UsageVersion",
							"1000000.0");
		put rc=;

    
		rc=metadata_newobj("Column",
                       curi2,
                       "Column3",
                       "Foundation",
                       uri,
                       "Columns");

		put rc=;
		put curi2=;

/* Add PublicType= and UsageVersion= attribute values to Column3. */
		rc=metadata_setattr(curi2, 
							"PublicType",
							"Column");
		put rc=;

		rc=metadata_setattr(curi2, 
			            "UsageVersion",
			            "1000000.0");
		put rc=;

/* Create an association between library and the table */

		rc=metadata_setassn(luri, 
							"Tables",
							"Append", 
							uri);
		put=rc;

	run;