BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

Hello,

 

I am using a proc http procedure to download an xml file from a specific web site.

I am able to import this xml file into a SAS dataset.  However, the issue I am facing is that some variable name are longer than 32 characters so I am loosing precious information.  The complete name can be found in the map file more precisely in the path .  Is there a way to put map information into a SAS dataset , work on it the redo the map file for future use.

 

Here's an example

        </COLUMN>
                
        <COLUMN name="QID2_TEXT_8cb70e63_1kek94049fwn8">
                        
            <PATH syntax="XPath">/Responses/Response/QID2_TEXT_8cb70e63_1kek94049fwnTopicHierarchy1</PATH>
                        
            <TYPE>character</TYPE>
                        
            <DATATYPE>string</DATATYPE>
                        
            <LENGTH>32</LENGTH>
                    
        </COLUMN>
            
    </TABLE>
    
</SXLEMAP>

So, if you look at COLUMN name=QID2_TEXT_8cb70e63_1kek94049fwn8 but the real value of that column is found in

PATH syntax=

 

PATH syntax="XPath">/Responses/Response/QID2_TEXT_8cb70e63_1kek94049fwnTopicHierarchy1</PATH>

 

so if you eliminate the 8cb70e63_1kek94049fwn string it should gives 

QID2_TEXT_TopicHierarchy1 which is the good column name.

 

Is there a way to do that in SAS

If I rename the column name do I need to eliminate the 8cb70e63_1kek94049fwn string from the Path syntax.

 

Please provide an example.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

It is not hard to read/write the XMLMAP file as a simple text file.

filename old 'xml.map';
filename new 'new_xml.map';
data _null_;
  infile old;
  file new;
  input;
  if left(_infile_)= '<COLUMN name="QID2_TEXT_8cb70e63_1kek94049fwn8">' then
    put '<COLUMN name="Topic">'
  ;
  else put _infile_;
run;

If you want to get fancy the map file is itself an XML file.  So you could use the XMLV2 engine to read it into a dataset (or set of datasets).  Then manipulate the data in the way you want and write out a new map file.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

To answer your last question first.

NO. 

Do NOT change the PATH setting that is what tells it where to LOOK in the XML.

 

Just change the NAME= attribute to whatever name you want.

 

TopicHierarchy looks like a better name to me.

Or perhaps just TOPIC.

The shorter the better, otherwise it is extremely painful to type programs. 

 

You can always put the longer text into the LABEL of the variable.  For some strange reason they call the label DESCRIPTION in the XMLMAP file.

<COLUMN name="Topic">
  <PATH syntax="XPath">/Responses/Response/QID2_TEXT_8cb70e63_1kek94049fwnTopicHierarchy1</PATH>
  <TYPE>character</TYPE>
  <DATATYPE>string</DATATYPE>
  <LENGTH>32</LENGTH>
  <DESCRIPTION>QID2_TEXT_8cb70e63_1kek94049fwnTopicHierarchy1</DESCRIPTION>
</COLUMN>

 

 

alepage
Barite | Level 11

we change the variable name manually but is there a way to do that with a SAS code

Tom
Super User Tom
Super User

It is not hard to read/write the XMLMAP file as a simple text file.

filename old 'xml.map';
filename new 'new_xml.map';
data _null_;
  infile old;
  file new;
  input;
  if left(_infile_)= '<COLUMN name="QID2_TEXT_8cb70e63_1kek94049fwn8">' then
    put '<COLUMN name="Topic">'
  ;
  else put _infile_;
run;

If you want to get fancy the map file is itself an XML file.  So you could use the XMLV2 engine to read it into a dataset (or set of datasets).  Then manipulate the data in the way you want and write out a new map file.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 879 views
  • 0 likes
  • 2 in conversation