We have a requirement to convert an xml data into sas dataset. The values are stored within attributes of the elements. We can only parse the element values and convert into dataset. Is there any solution to convert attribute values into dataset columns?
Sounds like you have XML stored in datasets (rather than in-line with the program).
If your data is actually in a database server like Oracle then using their built in tools to create a view would probably be the best.
Otherwise it is possible to write the data to text file and use SAS's XML engine to read it as a dataset. Will probably take some time to figure out how to generate the proper map to read it. Also SAS much prefers that the XML is nice a simple, but if it was that simple then you probably would have just stored it as variables to begin with.
filename xmlfile temp;
data _null_;
set have;
file xmlfile ;
put xmlvar ;
run;
libname xmlfile xml ;
data want ;
set xmlfile.table1 ;
run;
Use SAS XML Mapper tool. This will create the SAS code and XML maps needed to read your XML into a SAS dataset.
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.
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.