I have a series of simple PROC HTTP statements. I've noticed that, if one of the calls gets a Note: 502 Bad Gateway Note (rather than the Note: 200 OK) that the program runs to completion and I get missing data. So I devised a loop using this macro (https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1ietrp9bhfq65n1px6nxl6vp9df.htm#n1ietrp9bhfq65n1px6nxl6vp9df) but repeated the http statement instead of aborting.
%macro prochttp_check_return(code);
%if %symexist(SYS_PROCHTTP_STATUS_CODE) ne 1 %then %do;
%put ERROR: Expected &code., but a response was not received from the HTTP Procedure;
%get_CPI;%end;
%else %do;
%if &SYS_PROCHTTP_STATUS_CODE. ne &code. %then %do;
%put ERROR: Expected &code., but received &SYS_PROCHTTP_STATUS_CODE.
&SYS_PROCHTTP_STATUS_PHRASE.;
%get_CPI;%end;
%end;
%mend;
%macro get_CPI;
filename out5 "e:\sas data\out5.xml";
proc http
url='http://dataservices.imf.org/REST/SDMX_xml.svc/CompactData/IFS/M.IN.PCPI_IX.?startPeriod=2019&endPeriod=2024'
method="get" out=out5;
run;
%prochttp_check_return(200);
%mend get_CPI;
%get_CPI;
But, when I forced an error (by adding an extra character to the url - adding an extra dot "xml..scv"), it loops exactly 10 times, then gives a 200 OK note. But a check of the file shows that it is not OK, the call failed.
5539 %macro prochttp_check_return(code);
5540 %if %symexist(SYS_PROCHTTP_STATUS_CODE) ne 1 %then %do;
5541 %put ERROR: Expected &code., but a response was not received from the HTTP Procedure;
5542 %get_CPI;%end;
5543
5544 %else %do;
5545 %if &SYS_PROCHTTP_STATUS_CODE. ne &code. %then %do;
5546 %put ERROR: Expected &code., but received &SYS_PROCHTTP_STATUS_CODE.
5547 &SYS_PROCHTTP_STATUS_PHRASE.;
5548 %get_CPI;%end;
5549 %end;
5550 %mend;
5551
5552 %macro get_CPI;
5553 filename out5 "e:\sas data\out5.xml";
5554 proc http
5555 url='http://dataservices.imf.org/REST/SDMX_xml..svc/CompactData/IFS/M.IN.PCPI_IX.?startPeriod=2019&endPeriod=2024'
5556 method="get" out=out5;
5557 run;
5558
5559
5560 %prochttp_check_return(200);
5561 %mend get_CPI;
5562 %get_CPI;
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.26 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.26 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.25 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.25 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.27 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.27 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.26 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.25 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.27 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.25 seconds
cpu time 0.00 seconds
NOTE: 404 Not Found
ERROR: Expected 200, but received 404 Not Found
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.30 seconds
cpu time 0.03 seconds
NOTE: 200 OK
When I did get a 502 Bad Gateway note, there was no 10x repeat like above. Instead it went to a 200 OK note, and yet again, the call was bad in spite of the OK note.
2152 %macro prochttp_check_return(code);
2153 %if %symexist(SYS_PROCHTTP_STATUS_CODE) ne 1 %then %do;
2154 %put ERROR: Expected &code., but a response was not received from the HTTP Procedure;
2155 %get_CPI;%end;
2156
2157 %else %do;
2158 %if &SYS_PROCHTTP_STATUS_CODE. ne &code. %then %do;
2159 %put ERROR: Expected &code., but received &SYS_PROCHTTP_STATUS_CODE.
2160 &SYS_PROCHTTP_STATUS_PHRASE.;
2161 %get_CPI;%end;
2162 %end;
2163 %mend;
2164
2165 %macro get_CPI;
2166 filename out5 "e:\sas data\out5.xml";
2167 proc http
2168 url='http://dataservices.imf.org/REST/SDMX_xml.svc/CompactData/IFS/M.IN.PCPI_IX.?startPeriod=2019&endPeriod=2024'
2169 method="get" out=out5;
2170 run;
2171 %mend get_CPI;
2172
2173 %prochttp_check_return(200);
ERROR: Expected 200, but received 502 Bad Gateway
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.57 seconds
cpu time 0.00 seconds
NOTE: 200 OK
Is my code wrong or am I not understanding something about how the Return Codes work? Thanks
... View more