DATA Step, Macro, Functions and more

API connection Using SAS

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

API connection Using SAS

Dear Experts,

 

I have a problem using SAS API request.

 

tried the example from  https://www.lexjansen.com/pharmasug/2017/AD/PharmaSUG-2017-AD13.pdf

 

filename eqty "C:\PHARMSUG\EnergyQuantityIndex.json" lrecl=32000;

 

proc http url='http://www.bea.gov/api/data?&UserID=my-user API key&method=GETDATASETLIST&ResultFormat=JSON&'

method='get' out=eqty

ct="application/json";

run;

 

but it got the following error message.

ERROR: Unable to load transient module (Bridge failure).

NOTE: The SAS System stopped processing this step because of errors.

21 proc http

21 ! url='http://www.bea.gov/api/data?&UserID=xxxxxxxx-xxxxxxx-xxxxxxxxx&method=GETDATAS

21 ! ETLIST&ResultFormat=JSON&'

22 method='get' out=eqty

23 ct="application/json";

24 run;

 

can you help me to resolve the error message.

Current version: 9.04.01M5P091317

 

thanks,

kesete


Accepted Solutions
Solution
‎02-20-2018 10:27 AM
Community Manager
Posts: 3,463

Re: API connection Using SAS

@tekish - Either your version of SAS isn't 9.4m4 or higher (but you say it's m5, so that should be okay), OR there is an installation issue.  That's indicated by your first post -- did you check the SAS Note I referenced?

View solution in original post


All Replies
Community Manager
Posts: 3,463

Re: API connection Using SAS

[ Edited ]

Update: here's a SAS Note that might apply to you: http://support.sas.com/kb/61/513.html

 

Once you've followed the steps in the SAS note, try the simple test program that I shared here.  That will verify that you can use PROC HTTP to reach a public web service, retrieve a response, and parse the output.

Contributor
Posts: 70

Re: API connection Using SAS

Posted in reply to ChrisHemedinger

Chris, I'm trying to run this code in 9.4_M5 , but getting the error below. What am I missing?

filename resp temp;

/* Neat service from Open Notify project */
proc http
url="http://api.open-notify.org/astros.json"
method= "GET"
out=resp;
run;

/* Assign a JSON library to the HTTP response */
libname space JSON fileref=resp;

/* Print result, dropping automatic ordinal metadata */
title "Who is in space right now? (as of &sysdate)";
proc print data=space.people (drop=ordinalSmiley Happy;
run;

ERROR:

ERROR: The JSON engine cannot be found.
ERROR: Error in the LIBNAME statement.
56
57 /* Print result, dropping automatic ordinal metadata */
58 title "Who is in space right now? (as of &sysdate)";
59 proc print data=space.people (drop=ordinalSmiley Happy;
ERROR: Libref SPACE is not assigned.

Solution
‎02-20-2018 10:27 AM
Community Manager
Posts: 3,463

Re: API connection Using SAS

@tekish - Either your version of SAS isn't 9.4m4 or higher (but you say it's m5, so that should be okay), OR there is an installation issue.  That's indicated by your first post -- did you check the SAS Note I referenced?

Contributor
Posts: 70

Re: API connection Using SAS

Posted in reply to ChrisHemedinger

Chris,

 

I checked this reference check the SAS Note I referenced?. It is already installed my SAS current version.

Contributor
Posts: 70

Re: API connection Using SAS

[ Edited ]

Chris,

 

 the Below code runs with out any error.

 

Filename datain url 'http://chronicdata.cdc.gov/resource/dttw-5yxu.csv?topic=Overall%20Health&break_out=Overall';

 

 

proc import datafile=datain out=cdc_brfss_overall_health dbms=csv replace;

getnames=yes;

 

/* The following two procs would print out the schema and data itself, respectively */

/* proc contents; */

/* proc print data=cdc_brfss_excellent_health; */

/* remove non-states from the dataset */

data cdc_brfss_overall_health;

set cdc_brfss_overall_health;

if Locationabbr = 'UW' then delete;

if Locationabbr = 'US' then delete;

run;

 

/* Create a dataset that only has "Excellent" responses */

data cdc_brfss_excellent_health;

set cdc_brfss_overall_health;

if Response ^= 'Excellent' then delete;

run;

 

/* Sort the dataset (this is required for the non-paneled box plot coming up to work) */

proc sort data=cdc_brfss_excellent_health

out=cdc_brfss_excellent_health;

by Year;

 

 

/* Show a box plot with Year on the X-axis and the data_value on the Y-axis - excellent responses only */

title 'CDC BRFSS asked "How is your general health?"';

title2 'Data source: https://chronicdata.cdc.gov/d/dttw-5yxu';

proc boxplot data=cdc_brfss_excellent_health;

plot Data_value*Year /

BOXSTYLE=SCHEMATICID odstitle=title odstitle2=title2;

label Data_value = 'Crude % of Respondents Who Answered "Excellent"';

id Locationabbr;

 

/* Show a paneled box plot where each panel is a Response (excellent, very good, fair, poor) */

proc sgpanel data=cdc_brfss_overall_health;

panelby Response / novarname columns=5;

vbox Data_value / category=year datalabel=Locationabbr;

label Data_value = 'Crude Percentage'

 

run;

 

/* Show a frequency table to see how many data points each state has */

/* proc freq data=cdc_brfss_excellent_health;

tables Locationabbr / nocum;

run; */

 

thanks

Community Manager
Posts: 3,463

Re: API connection Using SAS

I'm glad that you have something working.  If you can't use PROC HTTP (which would be a better/faster method for using these APIs), then you probably still need to address the issue I shared in the SAS note I referenced.

Contributor
Posts: 70

Re: API connection Using SAS

Posted in reply to ChrisHemedinger

Chris,

 

It works with out any error.

 

thanks,

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 491 views
  • 0 likes
  • 2 in conversation