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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.