BookmarkSubscribeRSS Feed
ravimlmath
Fluorite | Level 6

Hi,

 

I am trying to make a get request which had query parameter and the parameter value has special characters but when i pass it to proc http url parameter the special character are being missread and the value is not being supplied correctly to the service

 

My url looks like this

http://myservice?name=abc+pqr&xyz

 

proc http
url="http://myservice?name=abc+pqr&xyz"
method=GET
ct="application/json"
in=input
out=resp
headerout=headout;
run; 

 

but the value is going as abc pqr. I tried url encoding also but it dosent work for + and & symbols.

Is there a way to encode urls when passing them to proc http

4 REPLIES 4
ChrisHemedinger
Community Manager

I think that your URL should work as-is with PROC HTTP.  Can you tell us what version of SAS you're using?  PROC HTTP has seen many improvements in SAS 9.4.

 

The + symbol in a URL is translated to whitespace -- that's by design.  If you need the + as part of your data, encode it as %2B.

 

Try your test with the free service httbin.org and see if it echos back what you expect.

 

%macro echoResp(fn=);
data _null_;
 infile &fn;
 input;
 put _infile_;
run;
%mend;

filename resp temp;
proc http
 method='GET'
 url='https://httpbin.org/anything?name=abc+pqr&xyz'
 out=resp;
run;

%echoResp(fn=resp);
/*
 returns:
 "args": {
    "name": "abc pqr", 
    "xyz": ""
  }
*/

/* encoded plus symbol */
proc http
 method='GET'
 url='https://httpbin.org/anything?name=abc%2Bpqr&xyz'
 out=resp;
run;

%echoResp(fn=resp);
/*
  returns:
   "args": {
    "name": "abc+pqr", 
    "xyz": ""
  },
*/

 

 

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
ravimlmath
Fluorite | Level 6

I am using SASv9.04.01M2P07232014

ChrisHemedinger
Community Manager

Great! Then try the test program I shared -- should reveal what you need.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
ravimlmath
Fluorite | Level 6

Thanks.. it works with encoded string..

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2777 views
  • 1 like
  • 2 in conversation