Hello,
I would like to expose some data one the web through a json rest api.
I have no idea how it could be done. (I have experience building Stored processes with SAS EG (EG 7.1 & SAS 9.3) but that's about it)
Is it as simple as making a STP like this?
data _null_;
file _webout;
put '...';
run;
I tried that and when going to the url of the STP in a browser I see the json data.
But when retrieving the data with javascript from a web page on another server I get a cross-origin CORS error.
XMLHttpRequest cannot load https://xxx.xxx.xxx/SASStoredProcess/guest?_program=/yyy/yyy/yyy. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://xxx.xxx.xxx' is therefore not allowed access.
$.ajax({ dataType: "json", url: "//xxx.xxx.xxx/SASStoredProcess/guest?_program=/yyy/yyy/yyy", // data: data, success: function(data) { console.log(data); } });
Is it possible to add the header "Access-Control-Allow-Origin:*" in the response?
Thanks!
Still have no idea if this is a good way for achieving this.
What happens when the STP gets more complicated and takes more than a fraction of a second to complete?
Is this REST?
Hello Mathias,
This is a perfectly valid way of coding a web service yourself. You also have valid concerns.
Here are a few takeway notes:
* Your web service works becasue you have manually logged on. Try to log out of SAS Stored Process Web Application and run the request, it will not work becasue SAS will ask you to authenticate when your ajax request won't handle that request.
* Your way of changing headers applies only to your webservice. This means you can't use the same method to log in to your webservice as SAS Logon manager will not have the correct headers.
* Default setting for SAS Web Server is to time out after one minute. It can be changed, but at the same time, would your users wait for at least 30 seconds to refresh a datasource on the screen? If web service takes more then a few seconds to fetch the data, something needs to change.
I have two solutions to suggest:
* Consider using an open source connector form Boemska: https://github.com/Boemska/h54s This is tried and tested way of getting data out SAS, but it requires certain level of access to the SAS platform.
* Analytium, the company that I am working for, has a solution in the pipeline that makes it easier to integrate software with SAS. It would be great if I could give you a quick demo over WebEx to see how Analytium could help you get the most out SAS. If you are interested, just let me know your timezone, availability and email by sending me a private message: Send Message to Vasilij Nevlev
Regards,
Vasilij
See if this helps. We ran into a CORS on a AWS server hosting the sas stored process web app.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.