BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
shlomiohana
Obsidian | Level 7
Hi,
How can i convert XML to URL with sas?

Example:
Xml:
<?xml version="1.0" encoding="UTF-8"?>
<SMF_REQUEST_PARAMS>
<customerIdType>1</customerIdType>
<customerId>312755468</customerId>
</SMF_REQUEST_PARAMS>

URL CONVERT:
%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%0A%3CSMF_REQUEST_PARAMS%3E%0A%0A%20%20%20%3CcustomerIdType%3E1%3C%2FcustomerIdType%3E%0A%0A%20%20%20%3CcustomerId%3E312755468%3C%2FcustomerId%3E%0A%0A%3C%2FSMF_REQUEST_PARAMS%3E

Thanks.
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
have='<?xml version="1.0" encoding="UTF-8"?>
<SMF_REQUEST_PARAMS>
<customerIdType>1</customerIdType>
<customerId>312755468</customerId>
</SMF_REQUEST_PARAMS>';
want=urlencode(have);
run;

Ksharp_0-1689250035854.png

 

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @shlomiohana,

 

You can use the URLENCODE function:

data have;
input xml $80.;
cards;
<?xml version="1.0" encoding="UTF-8"?>
<SMF_REQUEST_PARAMS>
<customerIdType>1</customerIdType>
<customerId>312755468</customerId>
</SMF_REQUEST_PARAMS>
;

data want;
set have end=last;
length url $1000;
url=catt(url,urlencode(trim(xml)));
if last;
retain url;
run;

If you really need the double linefeed characters (hex 0A) representing the line breaks, insert

if not last then url=catt(url,'%0A%0A');

before the subsetting IF statement if last.

 

Your sample output also shows some blanks (hex 20) after line 2 and 3. To reproduce this in this particular example, you could insert a second IF statement:

if _n_ in (2, 3) then url=catt(url,'%20%20%20');

but I don't think this is useful.

Ksharp
Super User
data have;
have='<?xml version="1.0" encoding="UTF-8"?>
<SMF_REQUEST_PARAMS>
<customerIdType>1</customerIdType>
<customerId>312755468</customerId>
</SMF_REQUEST_PARAMS>';
want=urlencode(have);
run;

Ksharp_0-1689250035854.png

 

SAS INNOVATE 2024

innovate-wordmarks-white-horiz.png

SAS is headed back 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.

Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

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.

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