BookmarkSubscribeRSS Feed
DMoovendhan
Quartz | Level 8
hi, I need to extract data from an XML file. Is there any way that I can do it without an XML map and without the default XML variables that comes in the dataset. Thanks, Moovendhan Devaraj
15 REPLIES 15
LinusH
Tourmaline | Level 20

Can you please motivate your requirement?

Data never sleeps
Reeza
Super User

Are you referring to an external XML map or one that SAS maps?

ballardw
Super User

A guess and likely not the most helpful if you have many files, but open the XML in a spreadsheet program. If the data looks "good" save to a CSV and import that  perhaps with datastep code to set variable names as you would like.

DMoovendhan
Quartz | Level 8

Hi,

 

the XML file is not properly organised when I opened it as an excel file.

 

I am attaching the XML file for your reference.

 

Thanks,

Moovendhan Devaraj

Ksharp
Super User

Yes. Data step can do that . But that depend on how complicated the XML file is .

Or you could check xml2 engine. Like :   libname x xml2 '......' automap=replace;

DMoovendhan
Quartz | Level 8

Let me try this, hope this works....

DMoovendhan
Quartz | Level 8

 tried this soultion and sas throws an error as below,

 

ERROR 22-7: Invalid option name AUTOMAP.

 

I am using sas version 9.3 in my windows PC. does this option work for you, or is it used in some different version of SAS.

BillM_SAS
SAS Employee

The AUTOMAP option was not available in the XMLV2 LIBNAME engine until the second maintenance release of SAS 9.3. Based on the error message, I suspect you are not at that maintenance level of SAS 9.3.

DMoovendhan
Quartz | Level 8

you are correct, I am using sas 9.3. Probably not that version that has auto map option.

 

Is there any way that I can have that enabled in the current version of SAS, is there any path that needs to be installed to enable this.

DMoovendhan
Quartz | Level 8

Sorry for the confusion,

 

I should have given more specific requirment.

 

I have zipped and attached an example XML, and this needs to be imported without an XML map.

 

I have to automate this in such a way that any xml file that is been provided needs to be imported without any issue.

The column names would change with different XML files.

Kindly help.

Ksharp
Super User

OK. Here is .

 

 

libname nhl xmlv2 '/folders/myfolders/LabReviewMicroSampleData.xml'
automap=replace
xmlmap='/folders/myfolders/NhlGenerate.map';
proc contents data=nhl._all_ nodetails;
run;
proc print data=nhl.Sex;run;
DMoovendhan
Quartz | Level 8

Hi Xia,

 

In this solution you have used 'nhlgenerate.map' import the data form the XML file.

 

Is there any way that we can import the data without any XML map been created?

 

When I tried creating a xml map using XML automap, I getting error due to unavailability of formats and informats. Is it possible for you to share the map, that you used?

Ksharp
Super User
xmlmap='/folders/myfolders/NhlGenerate.map';

is genereated by SAS . You can assign it  any name  like x.map yy.map . No need to consider about it.

If you SAS doesn't has such ability ,try SAS University Edition. 

BillM_SAS
SAS Employee

As noted, the easiest way to do this is with the XMLV2 LIBNAME engine and the AUTOMAP option. By using AUTOMAP=REPLACE, the map file is regenerated each time and is specific to the XML file specified. If you don't like the idea of keeping the map file around between runs, you can automatically throw it away by using a temporary map file:

 

filename test 'c:\LabReviewMicroSampleData.xml';
filename tempmap temp;
libname test xmlv2 xmlmap=tempmap automap=replace;

I had no problems using this method to create data sets from your posted XML file.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 15 replies
  • 3251 views
  • 3 likes
  • 6 in conversation