Convert xml into SAS dataset

Reply
Occasional Contributor
Posts: 8

Convert xml into SAS dataset

Hi all,

I am trying to convert xml file into sas dataset. I have tried like this. but I am getting error :ERROR: File  in.discharge.DATA does not exist. Can any one please guide me for this.

title1 'XML WORKSHOP EXERCISE #2';

libname in xml 'C:\workshop\ws119\XML\hosp_discharge.xml';

data discharge;

set in.discharge;

run;

Super User
Posts: 17,886

Re: Convert xml into SAS dataset

Try the following:

filename myxml "'C:\workshop\ws119\XML\hosp_discharge.xml";

filename mymap "'C:\workshop\ws119\XML\example_generate.map";

libname myxml xmlv2 automap=replace xmlmap=mymap;

proc contents data=myxml._all_;

run;

*check what the table name is here and then assign it;

data discharge;

set myxml.discharge;

run;

libname myxml;

filename myxml clear;

filename mymap clear;

Occasional Contributor
Posts: 8

Re: Convert xml into SAS dataset

Yes. I tried your code. i am getting error like this.

                         -------

                         22

ERROR: Libname MYXML is not assigned.

ERROR: Error in the LIBNAME statement.

ERROR 22-7: Invalid option name AUTOMAP.

16

17   proc contents data=myxml._all_;

18   run;

ERROR: Libname MYXML is not assigned.

Super User
Posts: 17,886

Re: Convert xml into SAS dataset

What version of SAS are you on?

Occasional Contributor
Posts: 8

Re: Convert xml into SAS dataset

9.3

Super User
Posts: 17,886

Re: Convert xml into SAS dataset

Post the full log/code and a sample XML file if you can?


Can you open the XML file in Excel?

Occasional Contributor
Posts: 8

Re: Convert xml into SAS dataset

Original Xml file :

<?xml version="1.0" encoding="windows-1252" ?>

- <TABLE>

- <SUBJECTS>

<FirstName>James</FirstName>

<Age>10</Age>

</SUBJECTS>

- <SUBJECTS>

<FirstName>Tom</FirstName>

<Age>12</Age>

</SUBJECTS>

- <SUBJECTS>

<FirstName>Joe</FirstName>

<Age>15</Age>

</SUBJECTS>

</TABLE>

Sas Program:

filename  test1 'D:\prathibha\xml _SAS\test1.xml';

filename  SXLEMAP 'c:\users\pmudiyala\xmi_SAS\T.MAP';

libname   test1 xmlv2 automap=replace xmlmap=SXLEMAP ;

/*

*  Catalog

*/

proc contents data=test1; run;

Log:

1

2    filename  test1 'D:\prathibha\xml _SAS\test1.xml';

3    filename  SXLEMAP 'C:\Users\pmudiyala\Desktop\T.MAP';

4    libname   test1 xmlv2 automap=replace xmlmap=SXLEMAP ;

                           -------

                           22

ERROR: Libname TEST1 is not assigned.

ERROR: Error in the LIBNAME statement.

ERROR 22-7: Invalid option name AUTOMAP.

5

6    /*

7     *  Catalog

8     */

9

10   proc contents data=test1; run;

NOTE: Writing HTML Body file: sashtml.htm

ERROR: File WORK.TEST1.DATA does not exist.

NOTE: Statements not processed because of errors noted above.

NOTE: PROCEDURE CONTENTS used (Total process time):

      real time           3.84 seconds

      cpu time            0.17 seconds

NOTE: The SAS System stopped processing this step because of errors.

Super User
Posts: 17,886

Re: Convert xml into SAS dataset

It works fine for me on SAS 9.3 TS1M2.

Both of these worked.  See the tip sheet here:

https://support.sas.com/rnd/base/xmlengine/XMLtipsheet.pdf

filename  test1 'C:\_localdata\temp\sample.xml';

filename  SXLEMAP 'C:\_localdata\sample.MAP';

libname   test1 xmlv2 automap=replace xmlmap=SXLEMAP ;

data want;

set test1.subjects;

run;

data want2;

set test1.table;

run;

libname test1;

filename test1 clear;

filename sxlemap clear;

libname   test1 xmlv2 'C:\_localdata\temp\sample.xml';

data subjects;

    set test1.subjects;

run;

libname test1;

Super User
Posts: 9,687

Re: Convert xml into SAS dataset

or try this special way . it doesn't need SAS9.3  .

data have;

infile cards length=len;

input x $varying200. len;

want=prxchange('s/<[^<>]*>//',-1,x);

cards4;

<?xml version="1.0" encoding="windows-1252" ?>

- <TABLE>

- <SUBJECTS>

<FirstName>James</FirstName>

<Age>10</Age>

</SUBJECTS>

- <SUBJECTS>

<FirstName>Tom</FirstName>

<Age>12</Age>

</SUBJECTS>

- <SUBJECTS>

<FirstName>Joe</FirstName>

<Age>15</Age>

</SUBJECTS>

</TABLE>

;;;;

run;

Xia Keshan

Ask a Question
Discussion stats
  • 8 replies
  • 755 views
  • 1 like
  • 3 in conversation