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;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

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;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
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;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
ChrisHemedinger
Community Manager

See a simple PROC HTTP test program here.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
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;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

SAS Innovate 2025: Register Now

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!

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
  • 6 replies
  • 3646 views
  • 3 likes
  • 2 in conversation