BookmarkSubscribeRSS Feed
ismahero1
Fluorite | Level 6

Hi,

 

I am using XML Mapper engine xmlv2.  I am using a map to load 2 or more XML files.  I would like to modify the map to have the file name as one of the variables.  Any knows how can I get the filenames as part of the variables in my dataset?

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

This is unclear. Please give an example of want you want.

 

Tom
Super User Tom
Super User

Are you asking if there is a way in your map file to specify that when you use it to convert an XML file to a SAS dataset that the name of the XML being converted? I would be very surprised if that is possible as why would the map file know anything about the source of the file that it is being used to parse?

 

You could do that in separate logic.  Let's setup an example by creating an XML file.

libname out xmlv2 'c:\downloads\class1.xml';
data out.class; set sashelp.class; run;
libname out clear;

Now let's read that back into a SAS dataset and use the PATHNAME() function to find the path that the libref being used.

libname in xmlv2 'c:\downloads\class1.xml';
data class;
  set in.class ;
  filename=pathname('in');
run;

Results:

Obs    Name            Sex         Age      Height      Weight           filename

  1    Alfred            M          14          69       112.5    c:\downloads\class1.xml
  2    Alice             F          13        56.5          84    c:\downloads\class1.xml
  3    Barbara           F          13        65.3          98    c:\downloads\class1.xml
  4    Carol             F          14        62.8       102.5    c:\downloads\class1.xml
  5    Henry             M          14        63.5       102.5    c:\downloads\class1.xml
  6    James             M          12        57.3          83    c:\downloads\class1.xml
  7    Jane              F          12        59.8        84.5    c:\downloads\class1.xml
  8    Janet             F          15        62.5       112.5    c:\downloads\class1.xml
  9    Jeffrey           M          13        62.5          84    c:\downloads\class1.xml
 10    John              M          12          59        99.5    c:\downloads\class1.xml
 11    Joyce             F          11        51.3        50.5    c:\downloads\class1.xml
 12    Judy              F          14        64.3          90    c:\downloads\class1.xml
 13    Louise            F          12        56.3          77    c:\downloads\class1.xml
 14    Mary              F          15        66.5         112    c:\downloads\class1.xml
 15    Philip            M          16          72         150    c:\downloads\class1.xml
 16    Robert            M          12        64.8         128    c:\downloads\class1.xml
 17    Ronald            M          15          67         133    c:\downloads\class1.xml
 18    Thomas            M          11        57.5          85    c:\downloads\class1.xml
 19    William           M          15        66.5         112    c:\downloads\class1.xml

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 859 views
  • 0 likes
  • 3 in conversation