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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.