BookmarkSubscribeRSS Feed
Mayt
Quartz | Level 8

Hi guys! I've tried to use proc http to call sas decision. It works well, but right now I need to specify access token myself. That means whenever the token gets changed, I need to edit my code. So the question is how can I retrieve the token from sas?

 

I generated sas token from the following link : https://blogs.sas.com/content/sgf/2023/02/07/authentication-to-sas-viya/

 

My code right now:

proc http 
METHOD="POST" url="mysasdecisionurl" in='{"inputs":[]}' ct = "applicationvnd.sas.microanalytic.module.step.input+json" out=resp oauth_bearer = sas_services; headers 'Authorization'= "My token"; run;

I found some solution from this link : https://communities.sas.com/t5/SAS-Programming/How-to-use-PROC-HTTP-with-OAUTH-to-get-an-access-toke... 

But it seems every time the code is executed, a new token will be generated. I just want to retrieve an old token, not to generate a new token.

2 REPLIES 2
dcmacedo
Obsidian | Level 7

I'm also having the same problem. I would like to know how to use the authentication token that the user made to access SASStudio itself.

In other words, being able to authenticate to the Viya APIs with the user's own credentials logged into SAS Studio.

Mayt
Quartz | Level 8

If you don't want users to put token every time they want to access sas product like me, in my case I use this code :

filename resp "your json file";
%let url = %nrstr("your publish sas product");
/*$one_json is your input*/
%let one_json = '{"inputs":[{"name": " ", "value": " "},{"name": " ", "value":" "}]}';
proc http
	url = &url.
	in = &one_json.
	out = resp
	method = post
	oauth_bearer = sas_services
	ct = "application/vnd.sas.microanalytic.module.step.input+json";
run;
		
/* read json and create it as a library named logdata */
libname logdata json "your json file";

 Or you can see my other blog: (https://communities.sas.com/t5/SAS-Programming/how-to-get-sas-access-token-in-proc-http/m-p/888299#M... ). There is solution from DavidHD that might help you.

 

Hope it helps 🙂

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1197 views
  • 0 likes
  • 2 in conversation