Presentation is loading. Please wait.

Presentation is loading. Please wait.

Writing and Reading XML files with SAS (Statistical Analysis System) What is SAS ? SAS Institute (or SAS, pronounced "sass") is an American developer of.

Similar presentations


Presentation on theme: "Writing and Reading XML files with SAS (Statistical Analysis System) What is SAS ? SAS Institute (or SAS, pronounced "sass") is an American developer of."— Presentation transcript:

1 Writing and Reading XML files with SAS (Statistical Analysis System) What is SAS ? SAS Institute (or SAS, pronounced "sass") is an American developer of analytics software based in Cary, North Carolina. SAS develops and markets a suite of analytics software (also called SAS), which helps access, manage, analyze and report on data to aid in decision-making.

2 How to write and read XML files with SAS? Make use of the XML libname engine. Libname engine translates SAS datasets to XML files (Input is SAS CODE and Output is an XML file). Libname translates XML files to SAS (Input is an XML file and Output is a SAS code).

3 Writing XML files with the SAS XML Libname engine let’s start by writing an XML file with SAS, and examine the XML output file. 1. data work.study_abc; 2. length patientid $10 patientheight 8 patientweight 8; 3. infile cards; 4. input patientid $ patientheight patientweight; 5. cards; 6. subj001 181 78 7. subj002.. 8. subj003 173 66 9. ; 10. run;

4 Writing XML files with the SAS XML Libname engine (cont’d) 11. 12.libname phuse xml 'c:\temp\study_abc.xml' ; 13. 14.data phuse.study_abc; 15. set work.study_abc; 16. run;

5 XML output file. subj001 181 78 subj002

6 XML output file(cont’d) subj003 173 66

7 Comment on the XML output file SAS names the root element of the XML file “TABLE”. The elements defining the observations of the datasets contain the name of the SAS dataset ”Study_ABC”. The elements nested in the observations are the names of the variables within the dataset. The value for each observation and variable is stored within a variable element. The missing values are presented with the “missing” attribute.

8 Reading XML files with the SAS XML Libname engine When reading XML files with the SAS XML libname engine, SAS expects the XML files to be in the following format: One root element (as is mandatory on a well formed XML). An element bundling the variable information per observation. The name of this element will be used to name the dataset. Element(s) within the observation element. These will become the SAS variables.

9 Reading XML files with the SAS XML Libname engine (cont’d) The following code will read in the XML file into a SAS dataset: 1.libname phuse xml 'c:\temp\study_abc.xml'; 2. 3. data work.study_abc; 4. set phuse.study_abc; 5. run;

10 Writing XML FILES and SCHEMAS The custom structure of an XML document is described via an XSD. XSD: X ML S chema D efinition. This XSD is referred to by SAS as the XML schema. With the SAS XML libname statement SAS offers the possibility to write the schema and the data. To utilize this functionality the option XMLMETA must be specified. This option can have the values SCHEMA, DATA and SCHEMADATA, where SCHEMA will write just the schema, DATA will write just the XML data, and SCHEMADATA will write both the SCHEMA and the XML data.

11 SAS code that produces an XML code that writes both schema and data The following example shows the SAS code to write both the schema and the data. 1.libname phuse xml 'c:\temp\study_abc.xml' xmlmeta=schemadata; 2. 3. data phuse.study_abc; 4. set work.study_abc; 5. run; The OUTPUT will be the 40 XML lines of code that follows:

12 The resulting XML (both schema and data combined ) cont’d “first 10 lines of code” 1. 2. 3. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 4. xmlns:od="urn:schemas-microsoft-com:officedata"> 5. 6. 7. 8. 9. 10. Notice the depth of indention for lines 5 &9

13 The resulting XML (both schema and data combined ) cont’d “Second 10 lines of code” 11. 12. <xs:element name="patientid" minOccurs="0" od:jetType="text" 13. od:sqlSType="nvarchar"> 14. 15. 16. 17. 18. <xs:element name="patientheight" minOccurs="0" od:jetType="double" 19. od:sqlSType="double" type="xs:double" /> 20. <xs:element name="patientweight" minOccurs="0" od:jetType="double" Notice the depth of indention for lines 12 and 17

14 The resulting XML (both schema and data combined ) cont’d “Third 10 lines of code” 21. od:sqlSType="double" type="xs:double" /> 22. 23. 24. 25. 26. subj001 27. 181 28. 78 29. 30. Notice the nested elements and their values in lines 26,27 and 28

15 The resulting XML (both schema and data combined ) cont’d “The Last 10 lines of code” 31. subj002 32. 33. 34. 35. 36. subj003 37. 173 38. 66 39. 40. Notice that the second subject (patient) has missing attributes, so no values appeared in the generated XML code (lines 31, 32 and 33). Notice that SAS names the root elemnt of the XML file “TABLE” (lines 2 and 40)


Download ppt "Writing and Reading XML files with SAS (Statistical Analysis System) What is SAS ? SAS Institute (or SAS, pronounced "sass") is an American developer of."

Similar presentations


Ads by Google