BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
rawagah
Obsidian | Level 7

Hello,

 

I am just trying to test parsing a JSON on SAS EG 8.3 (SAS 9.4) but I am getting an error that I haven't found a solution for. I appreciate the help.

 

filename resp temp;
 
/* Neat service from Open Notify project */
proc http 
 url="http://api.open-notify.org/astros.json"
/* method= "POST"*/
 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=ordinal:);
run;

And this is the error I get:

 

1                                                          The SAS System                              17:36 Sunday, August 21, 2022

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         %macro HTML5AccessibleGraphSupported;
15             %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) >= 0 %then ACCESSIBLE_GRAPH;
16         %mend;
17         FILENAME EGSR TEMP;
18         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
19             STYLE=HTMLBlue
20             NOGTITLE
21             NOGFOOTNOTE
22             GPATH=&sasworklocation
23             ENCODING=UTF8
24             options(rolap="on")
25         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
26         
27         filename resp temp;
28         
29         /* Neat service from Open Notify project */


30         proc http
31          url="http://api.open-notify.org/astros.json"
32         /* method= "POST"*/
33          out=resp;
34         run;

ERROR: The tcpSockRead call failed. The system error is 'The connection was reset by a peer.'.
ERROR: The tcpSockRead call failed. The system error is 'The connection was reset by a peer.'.
ERROR: Connection has been closed.
NOTE: PROCEDURE HTTP used (Total process time):
      real time           0.49 seconds
      cpu time            0.01 seconds
      
NOTE: The SAS System stopped processing this step because of errors.
35         
36         /* Assign a JSON library to the HTTP response */
37         libname space JSON fileref=resp;
NOTE: JSON data is only read once.  To read the JSON again, reassign the JSON LIBNAME.
ERROR: Physical file does not exist, F:\SASWork\_TD27192_BJHQPSAS01_\#LN00071.
ERROR: Error in the LIBNAME statement.
38         
39         /* Print result, dropping automatic ordinal metadata */
40         title "Who is in space right now? (as of &sysdate)";


41         proc print data=space.people (drop=ordinal:);
2                                                          The SAS System                              17:36 Sunday, August 21, 2022

ERROR: Libref SPACE is not assigned.
42         run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
43         
44         %LET _CLIENTTASKLABEL=;
45         %LET _CLIENTPROCESSFLOWNAME=;
46         %LET _CLIENTPROJECTPATH=;
47         %LET _CLIENTPROJECTPATHHOST=;
48         %LET _CLIENTPROJECTNAME=;
49         %LET _SASPROGRAMFILE=;
50         %LET _SASPROGRAMFILEHOST=;
51         
52         ;*';*";*/;quit;run;
53         ODS _ALL_ CLOSE;
54         
55         
56         QUIT; RUN;
57         
1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

 

Could it be that the machine that is trying to access the API requires a proxy in order to access the web?
You may want to ask a systems administrator if that is the case.
If so, you can use the proxyhost / port arguments on the PROC HTTP statement.

 

Here is a 2019 paper the PROC HTTP developer has wrote, which may prove helpful:

Paper SAS3232-2019
The ABCs of PROC HTTP
Joseph Henry, SAS Institute Inc., Cary, NC

https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf

Cheers,
Koen

View solution in original post

3 REPLIES 3
sbxkoenk
SAS Super FREQ

Hello,

 

Could it be that the machine that is trying to access the API requires a proxy in order to access the web?
You may want to ask a systems administrator if that is the case.
If so, you can use the proxyhost / port arguments on the PROC HTTP statement.

 

Here is a 2019 paper the PROC HTTP developer has wrote, which may prove helpful:

Paper SAS3232-2019
The ABCs of PROC HTTP
Joseph Henry, SAS Institute Inc., Cary, NC

https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf

Cheers,
Koen

rawagah
Obsidian | Level 7

Thank you Koen, I was able to use method="GET" after inputting the proxy info. 

 

However, I'm still not able to use method="POST", not sure if this has to do with proxy as well. 

ChrisHemedinger
Community Manager

@rawagah Is this POST attempt using the same service (which is a GET call by nature)?

 

Try a generic test using the free httpbin.org service, which I wrote about in this article. This service allows you to try all of the various HTTP verbs to see how they work with your code.

filename resp temp;
proc http
 url="https://httpbin.org/post"
 method="POST" 
 /* proxyhost= proxyport= if needed*/
 out=resp;
run;

%put HTTP Status code = &SYS_PROCHTTP_STATUS_CODE. : &SYS_PROCHTTP_STATUS_PHRASE.; 
 
data _null_;
 rc = jsonpp('resp','log');
run;

 

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 668 views
  • 3 likes
  • 3 in conversation