All,
I am new to SAS and have been trying to learn and appreciate the help of anyone who can guide me on this issue. I have an internal API which I have successfully accessed using R, I am trying to now learn how to the same using PROC HTTP. My R code that works successfully is provided below, I am also attaching my attempt of the SAS code:
RawResponse1 <- GET(RequestURL1, add_headers('Authorization' = paste0('Bearer ', AccessToken)))
In the above code, RequestURL1 and AccessToken are custom built. My attempt and rebuilding this in SAS is shown below:
filename ProjResp "/ProjApiResponse.txt"; * edited the filepath ;
Proc HTTP
URL = URLDes
Method ="get"
Out = ProjResp
ct = "Authorization" = "Bearer &AccessToken";
Run;
* URLDes is the custom URL equivalent to RequestURL1 in the previous case ;
And then did you SYMPUT the value into a macro variable? Your computed name in the DATA step won't be in scope by the time you get to the PROC HTTP step -- you have to store it in a macro variable. Try this:
Data _null_;
URLDes = &URLToUse || "/" || &ProjectID || "/" || "Prediction" || "/" || &PredictionID;
call symputx('URLDes',URLDes);
;
Run;
proc http
method="GET"
url = "&URLDes."
out=ProjResp;
headers
"Authorization"="Bearer &AccessToken.";
run;
You want the HEADERS statement in PROC HTTP.
I have a complex example here.
Your code would look like:
Proc HTTP
URL = URLDes
Method ="get"
Out = ProjResp ;
headers "Authorization" = "Bearer &AccessToken";
Run;
Thanks a lot for your response. I edited the code per your suggestion, please see below :
Proc HTTP
URL = URLDes
Method ="get"
Out = ProjResp ;
headers "Authorization" = "Bearer &AccessToken";
Run;
I receive the following errors and I don't understand what the errors mean. Could you kindly offer any further guidance ?
What's the value of URLDes? This should be a quoted string with with URL of the web service you're calling.
And I assume you have a macro variable with that's assigned with the value of you access token, eg:
%let AccessToken=123454678992ehgue;
See a simple PROC HTTP test program here.
Data _null_;
URLDes = &URLToUse || "/" || &ProjectID || "/" || "Prediction" || "/" || &PredictionID;
put URLDes;
Test = vtype(URLDes);
put Test= ;
%put &AccessToken;
Run;
From the steps shown above, URLDes is a valid hyperlink, it is saved as a character. So, wondering what the issue is
And then did you SYMPUT the value into a macro variable? Your computed name in the DATA step won't be in scope by the time you get to the PROC HTTP step -- you have to store it in a macro variable. Try this:
Data _null_;
URLDes = &URLToUse || "/" || &ProjectID || "/" || "Prediction" || "/" || &PredictionID;
call symputx('URLDes',URLDes);
;
Run;
proc http
method="GET"
url = "&URLDes."
out=ProjResp;
headers
"Authorization"="Bearer &AccessToken.";
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 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.
Ready to level-up your skills? Choose your own adventure.