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

Hi All,

I need to send and receive data using REST API. Can someone help me where should I start at. I am very good at SAS coding, but not familiar with API.

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
M_EEddlestone
SAS Employee

Base SAS has what you need.

 

Here are a couple of papers from SAS Global Forum that provide explanations and examples.

REST at Ease with SAS®: How to Use SAS to Get Your REST (2015 SAS Global Forum)

REST at Ease with SAS®: How to Use SAS to Get Your REST (2016 SAS Global Forum)

View solution in original post

9 REPLIES 9
Ksharp
Super User

You need SAS Viya .

mlogan
Lapis Lazuli | Level 10
Hi Ksharp, Thanks for your suggestion. Can you please tell me why SAS Viya? I hear some people saying PROC HTTP, JSON, DS2. How SAS Viya differ from them? What/How SAS Viya can accomplish better that Base SAS 9.4 can't do?

Thanks,
ChrisHemedinger
Community Manager

I think the reference to SAS Viya is for the other way: if you need to use REST APIs to access SAS analytics features from other applications, that's where SAS Viya comes in.  If you want to use SAS to access other APIs (like Google Analytics, Qualtrics, GitHub, and many others) -- then PROC HTTP provides a robust method.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
mlogan
Lapis Lazuli | Level 10
Hi Chris, All I need to do is retrieve 1000s of records through REST APIs. Analyse the dataset with product "SAS base with Access to ODBC" that I already have. Would you please tell me if I can accomplish my task with the product that I have which can support PROC HTTP and REST APIS? Thanks,
M_EEddlestone
SAS Employee

Base SAS has what you need.

 

Here are a couple of papers from SAS Global Forum that provide explanations and examples.

REST at Ease with SAS®: How to Use SAS to Get Your REST (2015 SAS Global Forum)

REST at Ease with SAS®: How to Use SAS to Get Your REST (2016 SAS Global Forum)

mich1
Obsidian | Level 7

Robot wink

From what I understand, if you can make the web service call from a single string in a browser, then PROC HTTP can do it...

 

Here is a really good reference without authentication:

https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/ 

 

Here are two examples with authentication:

 

1) Here is a JSON example that uses a token:

/*GET A LIST OF SURVEYS IN JSON FORMAT - This example is for the Qualtrics API*/
/*Running from BASE 9.4 M5 on Windows PC in Unicode Support - See Qualtrics API documentation for details on calls and formats*/


filename response temp encoding="utf-8" lrecl=1000000;
proc http
url="https://YOURQUALATRICSACCOUNTHERE/WRAPI/ControlPanel/api.php?Request=getSurveys&User=YOURUSERNAME&Token=YOURTOKEN&Version=2.4&Format=JSON"
method= "GET"
out=response;
run;
libname SURVEYS JSON fileref=response;
Data SURVEYS (KEEP= ID NAME STATUS);
set SURVEYS.ALLDATA;
Retain ID Name STATUS;
if P3 = 'ID' then ID = Value;
if P3 = 'Name' then Name = Value;
if P3 = 'Status' then do;
Status = Value;
output;
end;
run;

 

2) This API also can output in XML. To read XML you need to use the SAS XML mapper and refer to the XML file in your script; However, you must have an XML file to map-HaHa...which is probably why JSON is better

 

/*GET A SURVEY QUESTIONS IN XML FORMAT - I run this from a macro which gets the survey names from a call e.g. EXECUTE('%MACRONAMEHERE(SURVEY)') - Well sort of...see macro documentation for real syntax*/
filename quest temp encoding="utf-8" lrecl=1000000;
proc http
url="https://YOURQUALATRICSACCOUNTHERE/WRAPI/ControlPanel/api.php?Request=getSurvey&User=YOURUSERNAME&Token=YOURTOKEN&Version=2.4&Format=XML&SurveyID=&SURVEY"
method= "GET"
out=quest;
run;
filename MAP 'C:\YOURPCFOLDER\SURVEYXML.map';
libname quest xmlv2 xmlmap=MAP;
data WORK.Question;
set quest.Question;
run;

 

These actually work for me...so this is possible

 

- Bread Crumbs and Circuses for all

Bread Crumbs and Circuses for All
smikl
Calcite | Level 5

Hi @ChrisHemedinger 

 

is using the SAS Viya the only way of publishing a REST API to let's say trigger a SAS procedure from an external application?

If so, what is the SAS Integration Technologies for? (https://www.sas.com/sk_sk/software/integration-technologies.html)

 

Do you know what is the difference between those two in terms of API publishing?

 

Thanks!

ChrisHemedinger
Community Manager

@smikl No, you don't need SAS Viya.  You can use SAS BI Web Services with stored processes.  See this exampleAnd the SAS documentation.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
jklaverstijn
Rhodochrosite | Level 12

I use PROC HTTP for this. It has all the bells and whistles needed. If you receive json and you have SAS 9.4M4 (the latest maintenance release) you can then you can use the json libname engine to conveniently transform that intake a dataset. Otherwise there are a few alternative suggestions to accomplish that, using Groovy, DS2 or datasatep.

 

Hope this helps,

- Jan.

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!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 24290 views
  • 4 likes
  • 7 in conversation