BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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 ;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

6 REPLIES 6
ChrisHemedinger
Community Manager

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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
UdayGuntupalli
Quartz | Level 8

@ChrisHemedinger

          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 ? 

 

image.png

ChrisHemedinger
Community Manager

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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
UdayGuntupalli
Quartz | Level 8
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 

tI1p-YLmpMDkNfHs6e1NASTCNqzBxitqruK1KqEezOckgUDDX8An_AT8iEKgt9qpXuhNlvpJWOMshvVJm7ZqC3_pneDRZkXisEvHvytYmwWMAOqduAC6fdP6zUZlfETlxNib
zUabPhtGRie-c7RW1WAkg3lOviPDyUZQ31UjC9ES6vgojzjHmV6I75ngIdUtD22W6EGoR9enXPdW6H-BCzT-DqDZKBsQULrHauwm08IGP__tVwmzP85cEDf96h_eTS1jK4d1
Ydy67TT5T3FOADP31h5oCUIRZtUkytwL3lT_JxFPRN_tJpwXxa_xhwqJRisMaA
 
Test=C
ChrisHemedinger
Community Manager

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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 2637 views
  • 3 likes
  • 2 in conversation