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;
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.
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;
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!
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.