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;
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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.