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;

 

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;
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
PROC Star

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

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 499 views
  • 1 like
  • 5 in conversation