BookmarkSubscribeRSS Feed
jerry898969
Pyrite | Level 9

I have an xml file that was sent to me from an outside source.  What I need to do it parse it so I have all the tag and property info put into a table.

I have tried importing it as an xml file but the file isn't formatted correctly.  I have no say in how the file comes to me so I decided to import the file and pull the info out myself.

This is just a small example of some of the stuff within the file.

<prj name="Test Prj">

<Level1 name="L101B">

<codes val="1" label="Temp 1" />

<codes val="2" label="Temp 2" />

<codes val="3" label="Temp 3" />

.

.

.

</prj>

Some tags have up to 9 properties so I know a loop will do it but I can't figure out how to grab each lines of info.

Example output Table

Tag      Property1  Value1       Property2 Value2  ...

prj        name        "Test Prj"  

Level1  name         "L101B"

codes  val              "1"           label         "Temp 1"

codes  val              "2"           label         "Temp 2"

codes  val              "3"           label          "Temp 3"

Thank you for your help

4 REPLIES 4
Cynthia_sas
SAS Super FREQ


Hi:

  The XML Libname engine only works "out of the box" with very regular, non-hierarchical XML. Did you try turning your XML into a SAS dataset using the XML Mapper to map from XML "irregular" form to a SAS dataset?

  That might be worth a try. There is doc on how to use the XML Mapper and if you really get stumped, Tech Support can help. I'd try that road first before you parse this yourself.

  Why do you need to save the "container" tags like <prj> and <Level1>? It looks to me like the output structure would be a dataset with the name L101B and then it would have

code label

1    Temp1

2     Temp2

3    Temp3

or else the DATASET would be named PRJ and there would be a variable named L101B in the dataset. In any case, if you created a long and skinny dataset, then you could transpose it quite easily.

  Just a thought for an alternative approach.

cynthia

jerry898969
Pyrite | Level 9

Hi Cynthia,

Thank you so much for your reply.    I have to do this process in a sas program so I can't use the XML mapper.

What i'm trying to do is store this data in a sas dataset.

I have to have the output like the example I posted.  There is another process that takes this data set and uploads the data to a different database.

I don't think the scan function is going to work for my situation.  There are some that have label="""TEMP 1""" and i'm not sure how to parse that out.

Any other help you can give me would be appreciated.  I want to eventually make it a macro.

Thank you

Cynthia_sas
SAS Super FREQ

Well, you only build the XML map 1 time. Then, you could use it over and over. So the XML map is just a one-time step. but I'll have to think about it.....basically, you just want to strip out the tags???

Will there only be 1 Level tag? Or can you have multiple Level 1 tags???? Can you show an example of a tag that has 9 properties? Is it a code tag???

cynthia

jerry898969
Pyrite | Level 9

Hi Cynthia,

Thank you for your reply.  The issue has been resolved.  The data that was orginally sent to me was incorrect and they are working on correcting it and sending it in a different format.

Thank you once again for all your help

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 887 views
  • 0 likes
  • 2 in conversation