02-14-2013 10:52 AM
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">
<codes val="1" label="Temp 1" />
<codes val="2" label="Temp 2" />
<codes val="3" label="Temp 3" />
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
02-14-2013 11:39 AM
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
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.
02-14-2013 12:37 PM
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.
02-14-2013 09:10 PM
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???
02-22-2013 10:03 AM
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