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": ""
  },
*/

 

 

 

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
ravimlmath
Fluorite | Level 6

Thanks.. it works with encoded string..

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3206 views
  • 1 like
  • 2 in conversation