METADATA Procedure

Example 4: Fileref to a Temporary File with the IN= Argument

Features:

fileref in IN= argument

Other features:

DATA _NULL statement

comparison of DATALINES and PUT statements to submit method request

You might want to test your code without creating a permanent input XML file. You can use a DATA _NULL_ step to create a temporary input XML file.
The input file (whether temporary or permanent) can be created with the DATALINES or PUT statements. Advantages of using the DATALINES statement include:
  • DATALINES is easier to type.
  • You can enter XML without having to worry about quotation marks and other SAS interpreted strings.
PUT statements are useful when the string is complex or dynamic, with values substituted by DATA step logic.
Create filerefs. The input fileref is temporary.
filename myinput temp lrecl=256;
filename myoutput "c:\myxml\results\weeklyresults.xml" lrecl=256;
Submit the DATALINES statement to create a temporary file that contains a SAS Open Metadata Interface XML method request. Later in the example, the temporary input XML file is called by the procedure's IN= argument.
data _null_;
   file myinput;
   input;
   put _infile_ '';
   datalines;
<GetMetadataObjects>
   <Reposid>$METAREPOSITORY</Reposid>
   <Type>Column</Type>
   <Objects/>
   <Ns>SAS</Ns>
   <Flags>1</Flags>
   <Options/>
</GetMetadataObjects>
;;
run;
proc metadata
     in=myinput
     out=myoutput;
run;
Perform the same task with PUT statements. Alternatively, submit PUT statements to create a temporary file. Each PUT statement is one line in the temporary input XML file. This code references the same filerefs as the previous code, and produces the same output.
data _null_;
   file myinput;
   put "<GetMetadataObjects";
   put "   <Reposid>$METAREPOSITORY</Reposid>";
   put "   <Type>Column</Type>";
   put "   <Objects/>";
   put "   <Ns>SAS</Ns>";
   put "   <Flags>1</Flags>";
   put "   <Options/>";
   put "</GetMetadataObjects>";
run;
proc metadata
     in=myinput
     out=myoutput;
run;
Submit a more complex request in PUT statements.The GetMetadataObjects request sets the OMI_XMLSELECT (128), OMI_GETMETADATA (256), and OMI_TEMPLATES (4) flags, and specifies an <XMLSELECT search="string"/> XML element and templates that request specific Column attributes and associations, and specific attributes of associated objects.
data _null_;
  file myinput;
put '<GetMetadataObjects>';
put '<Reposid>$METAREPOSITORY</Reposid>';
put '<Type>Column</Type>';
put '<Objects/>';
put '<NS>SAS</NS>';
put '<Flags>388</Flags>';
put '<Options>';
put '<XMLSelect search="*[Table/PhysicalTable[@Id=''A5BCTYE3.B4000004'']]"/>';
put '<Templates>';
put '  <Column ColumnName="" BeginPosition="" ColumnLength="" ColumnType="" ';
put '     desc="" EndPosition="" IsDiscrete="" IsNullable="" MetadataCreated="" ';
put '     MetadataUpdated="" Name="" SASColumnLength="" SASColumnName="" ';
put '     SASColumnType="" SASExtendedLength="" SASFormat="" SASInformat="" ';
put '     SASPrecision="" SASScale="">';
put '  <AccessControls/>';
put '  <Properties/>';
put '  <PropertySets/>';
put ' </Column>';
put ' <AccessControlEntry Id="" Name=""/> ';
put ' <AccessControlTemplate Id="" Name="" Use=""/> ';
put ' <Property UseValueOnly="" PropertyName="" Delimiter="" DefaultValue=""/>';
put ' <PropertySet PropertySetName="" SetRole=""/> ';
put '</Templates>';
put '</Options>';
put '</GetMetadataObjects>';
run;

proc metadata
  in=myinput
  out=myoutput;
run;