LIBNAME Statement for the XML Engine

LIBNAME Statement Syntax

LIBNAME libref XML <'XML-document-path' > <XML-engine-options>;

Arguments

libref

is a valid SAS name that serves as a shortcut name to associate with the physical location of the XML document. The name must conform to the rules for SAS names. A libref cannot exceed eight characters.

Limitation: The maximum number of concurrent open librefs that you can have assigned to the XML engine is 20.
XML

is the engine name for the SAS XML engine that imports and exports an XML document.

Note:   At your site, the XML engine name could be different if your system administrator assigned a different nickname to the XML engine. See your system administrator for the correct XML engine nickname.  [cautionend]

'XML-document-path'

is the physical location of the XML document for export or import. Include the complete pathname, the filename, and the file extension. An example is 'C:\My Documents\XML\myfile.xml'. Enclose the physical name in single or double quotation marks.

Requirement: The external file specification must be a file, not a folder. The .xml extension is not assumed.
Tip: You can use the FILENAME statement in order to assign a fileref to be associated with the physical location of the XML document to be exported or imported.

If the fileref matches the libref, then you do not need to specify the physical location of the XML document in the LIBNAME statement. For example, the following code writes to the XML document Fred.XML:

filename bedrock 'C:\XMLdata\fred.xml';

libname bedrock xml;

proc print data=bedrock.fred;
run;

To specify a fileref for the XML document that does not match the libref, you can use the XMLFILEREF=fileref option. For example, the following code writes to the XML document Wilma.XML:

filename cartoon 'C:\XMLdata\wilma.xml';

libname bedrock xml xmlfileref=cartoon;

proc print data=bedrock.wilma;
run;

XML Engine Options

The following options are the basic options for the XML engine:

INDENT=integer

specifies the number of columns to indent each nested element in the exported XML document. The value can be from 0 (which specifies no indentation) through 32. This is a cosmetic specification, which is ignored by an XML-enabled browser.

Default: 3
Restriction: Use this option when exporting an XML document only.
FORMATACTIVE=YES | NO

specifies whether CDISC ODM CodeList elements, which contain instructions for transcoding display data in a CDISC ODM document, are to be converted to SAS variable formats, and vice versa.

In an import operation, specifying FORMATACTIVE=YES converts the CDISC ODM CodeList elements to the corresponding SAS formats, registers the SAS formats on the referenced variables, and stores the created SAS formats in the format catalog.

In an export operation, specifying FORMATACTIVE=YES converts SAS formats to the corresponding CDISC ODM CodeList elements.

In both import and export operations, specifying FORMATACTIVE=NO causes display data to be ignored.

Default: NO
Tip: By default, the format catalog is created in the Work library. If you want to store the catalog in a permanent library, use the FORMATLIBRARY= option.
Tip: When the format catalog is updated, the default behavior is for new SAS formats that are created by translating CDISC ODM CodeList elements to replace any existing SAS formats that have the same name. To prevent existing formats from being overwritten, specify FORMATNOREPLACE=YES.
FORMATLIBRARY=libref

specifies the libref of an existing SAS library in which to create the format catalog.

Restriction: Use this option only if you are importing from the CDISC ODM format type (that is, when you have specified XMLTYPE=CDISCODM) and when you have specified FORMATACTIVE=YES.
FORMATNOREPLACE=YES|NO

specifies whether to replace existing format entries in the format catalog search path in cases where an existing format entry has the same name as a format that is being created by the XML engine when it converts a CDISC ODM CodeList element.

When FORMATNOREPLACE=YES, the engine does not replace formats that have the same name.

When FORMATNOREPLACE=NO, the engine replaces formats that have the same name.

Restriction: Use this option only when you are importing an XML document that is in CDISC ODM format (that is, when you have specified XMLTYPE=CDISCODM).
Default: NO
OIMSTART=nnn

specifies a beginning reference number, which in the exported XML document will be incremented sequentially for catalog, schema, table, and column identification.

Default: 1
Deprecated: The OIMSTART= option is deprecated in SAS 9. The option will not be supported in a future release. Functionality will be provided with a different option.
XMLCONCATENATE | XMLCONCAT=NO | YES

specifies whether the file to be imported contains multiple, concatenated XML documents. Importing concatenated XML documents is useful, for example, if an application is producing a complete document per query/response as in a Web form.

Default: NO
Restriction: Use this option when importing an XML document only.
Restriction: Use XMLCONCATENATE=YES cautiously. If an XML document consists of concatenated XML documents, the content is not standard XML construction. The option is provided for convenience, not to encourage invalid XML format.
Featured in: Importing Concatenated XML Documents.
XMLDATAFORM=ELEMENT | ATTRIBUTE

specifies whether the tag for the element to contain SAS variable information (name and data) is in open element or enclosed attribute format. For example, if the variable name is PRICE and the value of one observation is 1.98, the generated output for ELEMENT is <PRICE> 1.98 </PRICE> and for ATTRIBUTE it is <COLUMN name="PRICE" value="1.98" />.

Default: ELEMENT
Restriction: Use this option when exporting an XML document only.
XMLDOUBLE=FORMAT | PRECISION

determines the precision of a numeric value by specifying whether you want the value to be controlled by an assigned SAS format or whether you want the stored raw value.

In SAS, numeric variables store values in floating-point format. Rarely though do you display numeric values as they are stored. Usually, a numeric variable has an assigned SAS format, which controls the written appearance of the values, making them more readable. For example, if the stored value is 12345.1234 and the SAS format best8.2 is assigned to the variable, SAS displays the value as 12345.12. When written, the SAS format reduces the number of digits.

When a numeric variable has an assigned SAS format, the default behavior of the XML engine is that the format controls the numeric values that are imported or exported. For example, using the stored value and SAS format example above, if you exported the value to an XML document, by default, the XML element would contain the truncated value 12345.12, not the stored raw value.

FORMAT

uses an assigned SAS format in order to control the value:

When exporting, the XML engine uses the assigned SAS format in order to control the values for a numeric variable. Note that an assigned SAS format could reduce the number of digits for a numeric value in the output.

When importing, the XML engine retrieves PCDATA (parsable character data) from the named element.

PRECISION

retains the precision of numeric values:

When exporting, the XML engine generates an attribute-value pair (of the form rawvalue="value"). SAS uses the base64 encoding of the stored machine representation. (The base64 encoding method converts binary data into ASCII text and vice versa and is similar to the MIME format.)

When importing, the XML engine retrieves the value from the rawvalue= attribute in the element, ignoring the PCDATA content of the element. Typically, you would use XMLDOUBLE=PRECISION to import an XML document when data content is more important than readability.

Default: FORMAT
Featured in: Exporting Numeric Values and Importing an XML Document with Numeric Values.
XMLFILEREF=fileref

is the SAS name that is associated with the physical location of the XML document to be exported or imported. To assign the fileref, use the FILENAME statement. For example, the following code writes to the XML document Wilma.XML:

filename cartoon 'C:\XMLdata\wilma.xml';

libname bedrock xml xmlfileref=cartoon;

proc print data=bedrock.wilma;
run;
Tip: The XML engine can access any data referenced by a fileref assigned by the FILENAME statement, including the URL access method.
XMLMETA=DATA | SCHEMADATA | SCHEMA

specifies whether to include metadata-related information in the exported markup, or specifies whether to import metadata-related information that is included in the input XML document.

Metadata-related information is metadata that describes the characteristics (types, lengths, levels, and so on) of columns within the table markup. Including the metadata-related information can be useful when exporting an XML document from a SAS data set to process on an external product.

DATA

ignores metadata-related information. DATA includes only data content in the exported markup and imports only data content in the input XML document.

SCHEMADATA

includes both data content and metadata-related information in the exported markup and imports both data content and metadata-related information in the input XML document.

SCHEMA

ignores data content. SCHEMA includes only metadata-related information in the exported markup and imports only metadata-related information in the input XML document.

Default: DATA
Aliases:
DATA

NONE, NO, IGNORE

SCHEMADATA

FULL, YES

Restriction: Use this option for the HTML and MSACCESS formats only.
Interaction: For XMLMETA=SCHEMADATA, if XMLSCHEMA= is specified, separate metadata-related information is written to the physical location specified with XMLSCHEMA=. The data content is written to the physical location of the XML document specified in the LIBNAME statement. If XMLSCHEMA= is not specified, the metadata-related information is embedded with the data content in the XML document.
Featured in: Exporting an XML Document Containing a SAS User-Defined Format and Exporting an XML Document Containing SAS Dates, Times, and Datetimes.

Note:   Prior to SAS 9, the functionality for the XMLMETA= option used the keyword XMLSCHEMA=. SAS 9 changed XMLSCHEMA= to XMLMETA=. SAS 9.1 continues the functionality for XMLMETA= and adds new functionality using XMLSCHEMA=.  [cautionend]

XMLPROCESS=CONFORM | RELAX

determines how the XML engine processes character data that does not conform to W3C specifications.

CONFORM

requires that the XML conform to W3C specifications. W3C specifications state that for character data, certain characters such as the left angle bracket (<), the ampersand (&), and the apostrophe (') must be escaped using character references or strings like &amp;. For example, to allow attribute values to contain both single and double quotation marks, the apostrophe or single-quotation mark character (') can be represented as &apos; and the double-quotation mark character (") can be represented as &quot;.

RELAX

allows for character data that does not conform to W3C specifications to be accepted. That is, non-escaped characters such as the apostrophe, double quotation marks, and the ampersand are accepted in character data.

Restriction: Non-escaped angle brackets in character data are not accepted.
Restriction: Use XMLPROCESS=RELAX cautiously. If an XML document consists of non-escaped characters, the content is not standard XML construction. The option is provided for convenience, not to encourage invalid XML format.
Default: CONFORM
Featured in: Importing an XML Document with Non-Escaped Character Data.
XMLSCHEMA=fileref|'external-file'

specifies an external file to contain metadata-related information.

fileref

is the SAS name that is associated with the physical location of the output file. To assign a fileref, use the FILENAME statement.

'external-file'

is the physical location of the file to contain the metadata-related information. Include the complete pathname and the filename. Enclose the physical name in single or double quotation marks.

Restriction: Use this option when exporting an XML document only and with XMLMETA=SCHEMADATA specified.
Restriction: Use this option for the GENERIC and MSACCESS formats only.
Interaction: If XMLMETA=SCHEMADATA and XMLSCHEMA= is specified, the data is written to the physical location of the XML document specified in the LIBNAME statement, and separate metadata-related information is written to the physical location specified with XMLSCHEMA=. If XMLSCHEMA= is not specified, the metadata-related information is embedded with the data content in the XML document.
Featured in: Exporting an XML Document with Separate Metadata.
XMLTYPE=GENERIC | ORACLE | OIMDBM | EXPORT | HTML | MSACCESS | CDISCODM

specifies the format type:

Default: GENERIC
Tip: You can control the markup by specifying options such as INDENT=, XMLDATAFORM=, XMLMETA= (when applicable), and TAGSET=.

GENERIC

a simple, well-formed XML format. The XML document consists of a root (enclosing) element and repeating element instances as shown in the following XML document. GENERIC determines a variable's attributes from the data.

Requirement: When importing, the GENERIC format type requires a specific physical structure. See Understanding the Required Physical Structure for an XML Document to Be Imported Using the GENERIC Format Type.
Featured in: Exporting an XML Document Containing SAS Dates, Times, and Datetimes, Exporting Numeric Values, Importing an XML Document Using the GENERIC Format Type, and several examples throughout the document.
ORACLE

is the XML format for the markup standards equivalent to the Oracle8iXML implementation, as shown in the following XML document. The number of columns to indent each nested element is one, and the enclosing element tag for the contents of the SAS data set is ROWSET.

Featured in: Exporting an XML Document for Use by Oracle.
OIMDBM

is the XML format for the markup standards supported by the Open Information Model (Database Schema Model) proposed by the Metadata Coalition (MDC) as vendor and technology independent, conforming to the 1.0 specification. The XML markup contains metadata that is used in operational and data warehousing environments.

Deprecated: The OIMDBM format type is deprecated in SAS 9. The format type will not be supported in a future release. Functionality will be provided with a different format type.
EXPORT

is an alias to specify the XML format that is most commonly used in the industry. In SAS 9.1, specifying XMLTYPE=EXPORT is the same as specifying XMLTYPE=OIMDBM. Future releases will upgrade this format specification as needed.

HTML

is the HyperText Markup Language format. The XML engine generates HTML table markup, intended to facilitate viewing data in a tabular format.

Restriction: XMLTYPE=HTML is available for exporting only.
Deprecated: The HTML type is deprecated beginning in SAS 9.1.3. The HTML type will not be supported in some future release. Equivalent functionality can be achieved by specifying a tagset. See Defining and Using a Customized Tagset to Export an HTML Document.
MSACCESS

is the XML format for the markup standards supported for a Microsoft Access database (.mdb). If the Microsoft Access file contains metadata-related information, then you must specify MSACCESS rather than the default GENERIC format type. If there is an embedded XML schema, specifying MSACCESS and the XMLMETA=SCHEMADATA option causes a variable's attributes to be obtained from the embedded schema. If there is not an embedded schema, MSACCESS uses default values for attributes.

Interaction: When importing, MSACCESS supports Microsoft Access 2002 and 2003 databases. When exporting, use the TAGSET= option and specify TAGSETS.SASXMAC2002 for Microsoft Access 2002 or TAGSETS.SASXMAC2003 for Microsoft Access 2003.
Featured in: Importing an XML Document Created by Microsoft Access.
CDISCODM

is the XML format for the markup standards that are defined in the Operational Data Model (ODM) that was created by the Clinical Data Interchange Standards Consortium (CDISC). The XML engine supports the ODM 1.2 schema specification. ODM supports the electronic acquisition, exchange, and archiving of clinical trials data and metadata for medical and biopharmaceutical product development.

Tip: Use the FORMATACTIVE=, FORMATNOREPLACE=, and FORMATLIBRARY= options to specify how display data are read and stored in the target environment.
Featured in: Importing a CDISC ODM Document and Exporting an XML Document in CDISC ODM Format.

Statement Options for National Language Support

The following options are for National Language Support (NLS), which is the ability of a software program to handle more than one language, country, and cultural setting.

CAUTION:
These options should be used with caution.

If you are unfamiliar with character sets, encoding methods, or translation tables, do not use these options without proper technical advice.   [cautionend]

ODSCHARSET=character-set

specifies the character set to use for the output file. A character set includes letters, logograms, digits, punctuation, symbols, and control characters that are used for display and printing. An example of a character set is ISO-8859-1.

Restriction: Use this option when exporting an XML document only.
Tip: The combination of the character set and translation table (encoding method) results in the file's encoding.
See: For more information about character sets, see the SAS National Language Support (NLS): User's Guide.
ODSTRANTAB=table-name

specifies the translation table to use for the output file. The translation table (encoding method) is a set of rules that are used to map characters in a character set to numeric values. An example of a translation table is one that converts characters from EBCDIC to ASCII-ISO. The table-name can be any translation table that SAS provides or any user-defined translation table. The value must be the name of a SAS catalog entry in either the SASUSER.PROFILE catalog or the SASHELP.HOST catalog.

Restriction: Use this option when exporting an XML document only.
Tip: The combination of the character set and translation table results in the file's encoding.
See: For more information on translation tables, see the SAS National Language Support (NLS): User's Guide.
XMLENCODING=encoding-value

overrides the SAS data set's encoding for the output file.

Restriction: Use this option when exporting an XML document only.
Tip: The combination of the character set and translation table (encoding method) results in the file's encoding.
Tip: When using FTP to transfer an exported XML document, transfer the file in ASCII (text) mode if you used the default encoding or binary mode if you specified an encoding value.
See: For more information about encoding and a list of encoding values, see the SAS National Language Support (NLS): User's Guide.

XML Engine Advanced Options

The following advanced options provide customization:

METAPASS=password

specifies the password that corresponds to the user identification on the SAS Metadata Server. The maximum length is 512 characters.

The network protocol determines whether a password is required. If the protocol is COM, a password is not required; if the protocol is BRIDGE (which is the default), a password is required. If this option is not specified and the protocol is BRIDGE, the value is obtained from the METAPASS= system option. See the SAS Language Reference: Dictionary for information on the METAPASS= system option.

METAPORT=number

specifies the TCP port that the SAS Metadata Server is listening to for connections. An example is metaport=5282.

The network protocol determines whether a port number is required. If the protocol is COM, a port number is not required. If the protocol is BRIDGE (which is the default), a port number is required. If this option is not specified and the protocol is BRIDGE, the value is obtained from the METAPORT= system option or defaults to 9999. See SAS Language Reference: Dictionary for information on the METAPORT= system option.

METAREPOSITORY=name

specifies the name that is assigned to a specific SAS Metadata Repository to use on the SAS Metadata Server. The maximum length is 32,000 characters. An example is metarepository=myrepos. If a name is not specified, the value is obtained from the METAREPOSITORY= system option. See the SAS Language Reference: Dictionary for information on the METAREPOSITORY= system option.

METASERVER=address

specifies the network IP (Internet Protocol) address of the computer that hosts the SAS Metadata Server. An example is metaserver=d441.na.sas.com. The maximum length is 256 characters.

The network protocol determines whether an IP address is required. If the protocol is COM and the server is on a local machine, an IP address is not required. If the protocol is COM and the server is not local (DCOM services) or the protocol is BRIDGE, an IP address is required. If this option is not specified and the protocol is specified as COM on the LIBNAME statement, this indicates a local server and no IP address will be used to connect to the server. Otherwise, if this option is not specified, the value is obtained from the METASERVER= system option. See the SAS Language Reference: Dictionary for information on the METASERVER= system option.

METAUSER=id

specifies the user identification for logging into the SAS Metadata Server. The maximum length is 256 characters.

The network protocol determines whether a user identification is required. If the protocol is COM, a user identification is not required; if the protocol is BRIDGE (which is the default), a user identification is required. If this option is not specified and the protocol is BRIDGE, the value is obtained from the METAUSER= system option. See the SAS Language Reference: Dictionary for information on the METAUSER= system option.

METAXMLMAP=object-name

is the name of a specific metadata object that is assigned to an XMLMap in a SAS Metadata Repository. The object defines the XMLMap, which is an XML document that you create that contains specific XMLMap syntax. The syntax tells the XML engine how to interpret the XML markup for importing or how to generate XML markup for exporting an XML document. The ID can be up to 17 characters. An example is metaxmlmap="MyXMLMap". See Using XMLMap Manager to Manage XMLMaps as Metadata Objects for information on how to import and create XMLMap metadata objects.

ODSRECSEP= DEFAULT | NONE | YES

controls the generation of a record separator that marks the end of a line in the output XML document.

DEFAULT

enables the XML engine to determine whether to generate a record separator based on the operating environment where you run the SAS job.

The use of a record separator varies by operating environment.

Recommendation: If you do not transport XML documents across environments, use the default behavior.
NONE

specifies to not generate a record separator.

The XML engine uses the logical record length of the file that you are writing to and writes one line of XML markup at a time to the output file.

Requirement: The logical record length of the file that you are writing to must be at least as long as the longest line that is produced. If the logical record length of the file is not long enough, then the markup might wrap to another line at an inappropriate place.
Limitation: Transporting an XML document that does not contain a record separator can be a problem. For example, FTP needs a record separator in order to transfer data properly in ASCII (text) mode.
YES

specifies to generate a record separator.

Tip: Most transfer utilities will interpret the record separator as a carriage return sequence. For example, using FTP in ASCII (text) mode to transport an XML document that contains a record separator results in properly constructed line breaks for the target environment.
Default: The XML engine determines whether to generate a record separator based on the operating environment where you run the SAS job.
Restriction: Use this option when exporting an XML document only.
TAGSET=tagset-name

specifies the name of a tagset in order to override the default tagset that is used by the format type specified with XMLTYPE=. For example, by default, XMLTYPE=GENERIC uses the tagset TAGSETS.SASXMOG, which uses the variable name to enclose the contents of a SAS variable (for example, <STUDENT> and </STUDENT>) and the name of the data set to enclose the contents of a SAS observation (for example, <GRADES> and </GRADES>). For more information on tagsets, see Understanding and Using Tagsets for the XML Engine.

To change the tags that are produced, you can create a customized tagset and specify it with the TAGSET= option. For information about creating customized tagsets, see PROC TEMPLATE in the SAS Output Delivery System: User's Guide.

Restriction: Use this option when exporting an XML document only.
Restriction: Use this option with caution. If you are unfamiliar with XML output formats, do not use this option.
Featured in: Using a SAS Tagset to Remove White Spaces in Output XML Markup and Defining and Using a Customized Tagset to Use Labels in Node Names.

CAUTION:
If you alter the tagset when exporting an XML document and then attempt to import the XML document generated by that altered tagset, the XML engine might not be able to translate the XML markup back to SAS proprietary format.   [cautionend]
XMLMAP=fileref | 'XMLMap'

specifies an XML document that you create that contains specific XMLMap syntax. The syntax tells the XML engine how to interpret the XML markup for importing. The XMLMap syntax is itself XML markup. See Creating an XMLMap for the XML tag names and descriptions.

fileref

is the SAS name that is associated with the physical location of the XMLMap. To assign a fileref, use the FILENAME statement.

'XMLMap'

is the physical location of the XMLMap. Include the complete pathname and the filename. It is suggested that you use the filename extension .map. Enclose the physical name in single or double quotation marks.

For example, the following statements import an XML document named MY.XML and specify the XMLMap named MY.MAP, which contains specific XMLMap syntax. The XML engine interprets the XML document as a SAS data set (table) named MY. In this example, XMLMAP= is used as an option in the LIBNAME statement:

libname test xml 'C:\XMLdata\my.xml' xmlmap='C:\XMLdata\my.map';

proc print data=test.my;
run;
Tip: You can also specify XMLMAP= as a data set option. The following example uses XMLMAP= as a data set option and also uses a fileref that is assigned to the XMLMap:

filename map 'C:\XMLdata\my.map';

libname test xml 'C:\XMLdata\my.xml';

proc print data=test.my (xmlmap=map);
run;
Featured in: Importing XML Documents Using an XMLMap.

space
Previous Page | Next Page | Top of Page