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

Hello,

I run the following code:

filename resp temp;

proc http
 url="https://https-url.com"
 method="GET"
 out=resp;
run;

The resp file contains:

<?xml version="1.0" encoding="UTF-8"?><SMF_REPLY><SMF_SERVICE_NAME>CREATE_INTERACTION</SMF_SERVICE_NAME><SMF_REQUEST_ID>4VF1

o8j/4=</SMF_REQUEST_ID><SMF_RETURN_CODE>1</SMF_RETURN_CODE><SMF_RETURN

_MESSAGE>SMF-I-1-SUCCESS [SEND successful]</SMF_RETURN_MESSAGE></SMF_REPLY>

 

I want to create a table that will be created dynamically according to the tags that will be in the resp file. 

 

for example:

SMF_SERVICE_NAME SMF_REQUEST_ID SMF_RETURN_CODE

SMF_RETURN_MESSAGE

CREATE_INTERACTION

4VF1o8j/4=

1 SMF-I-1-SUCCESS [SEND successful]

 

If there is an additional tag in the resp file, a field will be added to the table automatically.

 

thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Below code works for me

filename resp temp;
options parmcards=resp;
parmcards4;
<?xml version="1.0" encoding="UTF-8"?>
<SMF_REPLY>
  <SMF_SERVICE_NAME>CREATE_INTERACTION</SMF_SERVICE_NAME>
  <SMF_REQUEST_ID>4VF1o8j/4=</SMF_REQUEST_ID>
  <SMF_RETURN_CODE>1</SMF_RETURN_CODE>
  <SMF_RETURN_MESSAGE>SMF-I-1-SUCCESS [SEND successful]</SMF_RETURN_MESSAGE>
</SMF_REPLY>
;;;;

filename map temp;
libname resp xmlv2 automap=replace xmlmap=map;
proc print data=resp.smf_reply;
run;

Patrick_0-1700351465030.png

 

If you've got multiple such response files to read in the same SAS session that all have the same structure then I'd be using automap=reuse in the libname statement.

 

 

 

View solution in original post

8 REPLIES 8
ChrisHemedinger
Community Manager

If this is indeed a sample of the response, it's XML content. You can use the XML libname engine to view this as data. Try this to get started:

 

libname data XMLv2 resp;
proc datasets lib=data; quit;

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
shlomiohana
Obsidian | Level 7

Hi,

 

I ran libname data xmlv2 resp; and got several errors:

 

ERROR: Libref DATA is not assigned.

ERROR: Error in the LIBNAME statement.

ERROR 23-7: Invalid value for the RESP option.

 

ChrisHemedinger
Community Manager

See the documentation for the XML libname engine.

 

If you assign your PROC HTTP output to resp, then this should work:

libname resp xmlv2;
proc datasets lib=resp; quit;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
shlomiohana
Obsidian | Level 7
Hi,

I ran libname resp xmlv2; and got several errors:

Error: PCDATA content found outside column/table boundary. content is CREATE_INTERACTION
Error: XML data is not in a format supported natively by the XML libname engine. Files of this type may require an XMLMap to be input properly.
shlomiohana
Obsidian | Level 7
I would appreciate help on how to solve the issue?
Quentin
Super User

Ugh, I thought everything was returning JSON by now.  

 

I never dealt much with XML, but if I had to do it, I would start by searching lexjansen.com index of user group papers, for XML MAP.  This was a popular topic not that many years ago.

 

https://www.lexjansen.com/search/searchresults.php?q=xml+map

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
Tom
Super User Tom
Super User

If the responses are simple, like your example, then just parse it using a simple data step.

Let's convert your example into a file.

filename resp temp;
options parmcards=resp;
parmcards4;
<?xml version="1.0" encoding="UTF-8"?><SMF_REPLY>
<SMF_SERVICE_NAME>CREATE_INTERACTION</SMF_SERVICE_NAME><SMF_REQUEST_ID>4VF1o8j/4=</SMF_REQUEST_ID>
<SMF_RETURN_CODE>1</SMF_RETURN_CODE>
<SMF_RETURN_MESSAGE>SMF-I-1-SUCCESS [SEND successful]</SMF_RETURN_MESSAGE>
</SMF_REPLY>
;;;;

And try reading it.

data want;
  infile resp dsd dlm='<' recfm=f lrecl=1000000 ;
  input @'<SMF_RETURN_CODE>' code +(-1) 
        @'<SMF_RETURN_MESSAGE>' message :$200.
  ;
run;

Result

Obs    code                 message

 1       1     SMF-I-1-SUCCESS [SEND successful]

Patrick
Opal | Level 21

Below code works for me

filename resp temp;
options parmcards=resp;
parmcards4;
<?xml version="1.0" encoding="UTF-8"?>
<SMF_REPLY>
  <SMF_SERVICE_NAME>CREATE_INTERACTION</SMF_SERVICE_NAME>
  <SMF_REQUEST_ID>4VF1o8j/4=</SMF_REQUEST_ID>
  <SMF_RETURN_CODE>1</SMF_RETURN_CODE>
  <SMF_RETURN_MESSAGE>SMF-I-1-SUCCESS [SEND successful]</SMF_RETURN_MESSAGE>
</SMF_REPLY>
;;;;

filename map temp;
libname resp xmlv2 automap=replace xmlmap=map;
proc print data=resp.smf_reply;
run;

Patrick_0-1700351465030.png

 

If you've got multiple such response files to read in the same SAS session that all have the same structure then I'd be using automap=reuse in the libname statement.

 

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 8 replies
  • 4392 views
  • 1 like
  • 5 in conversation