使用 SAS EG 通过代理从 API 下载 JSON 文件
Download JSON File from API via Proxy using SAS EG
我正在尝试使用来自瑞士当局的 API 从公司网络内对地址进行地理编码。我的公司使用带有用户名和密码的代理服务器。我是 SAS EG 的新手,这是我到目前为止的代码(我必须匿名化一些东西才能被允许 post 这里):
filename response temp;
options set=SSL_USE_SNI=1;
options set=SSL_SNI_HOSTNAME="api3.geo.admin.ch";
proc http
url = 'https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText=Bahnhofstrasse %201%20Zürich&type=locations'
method='GET'
proxyhost = 'http://OURPROXYHOST.ch'
proxyport = 8080
proxyusername = '***'
proxypassword= '***'
out= response
ct = "application/json";
run;
然而,日志不会抛出任何错误或警告,并且当 运行 代码时我没有看到输出文件。如果我在浏览器中输入 url 就可以了。
我正在使用 SAS EG 7.15 HF7 (7.100.5.6177)(64 位)。我希望你们能在这里帮助我。
输出的headers是什么样子的,用户HEADEROUT=看看
示例代码(虽然没有代理)
filename response temp;
filename headers temp;
proc http
url = "https://worldpopulationreview.com/static/states/abbr-name.json"
method = "get"
out = response
ct = "application/json"
headerout = headers
;
data _null_;
infile headers;
input;
put _infile_;
run;
data _null_;
infile response obs=10;
input;
put _infile_;
run;
* libref name same as fileref pointing to json content;
libname response json;
proc copy in=response out=work;
run;
日志
93 headerout = headers
94 ;
95
NOTE: 200 OK
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.04 seconds
cpu time 0.00 seconds
96 data _null_;
97 infile headers;
98 input;
99 put _infile_;
100 run;
NOTE: The infile HEADERS is:
Filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD4224_HELIUM_\#LN00067,
RECFM=V,LRECL=32767,File Size (bytes)=531,
Last Modified=05Nov2020:09:39:53,
Create Time=05Nov2020:09:39:53
HTTP/1.1 200 OK
Date: Thu, 05 Nov 2020 14:39:55 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
content-disposition: inline; filename="abbr-name.json"
cache-control: public, max-age=0, must-revalidate
content-length: 1057
access-control-allow-origin: *
etag: W/"672e384a87acd2f6547e5127fde8f2fe74c991498d7b468b1e439c3860554ea8"
accept-ranges: bytes
x-vercel-cache: HIT
age: 189
server: Vercel
x-vercel-id: cle1::fz9dn-1604587195926-0957f649b2c8
strict-transport-security: max-age=63072000
NOTE: 16 records were read from the infile HEADERS.
The minimum record length was 0.
The maximum record length was 74.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
101
102 data _null_;
103 infile response obs=10;
104 input;
105 put _infile_;
106 run;
NOTE: The infile RESPONSE is:
Filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD4224_HELIUM_\#LN00066,
RECFM=V,LRECL=32767,File Size (bytes)=1057,
Last Modified=05Nov2020:09:39:53,
Create Time=05Nov2020:09:39:53
{
"AL": "Alabama",
"AK": "Alaska",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
"DC": "District Of Columbia",
NOTE: 10 records were read from the infile RESPONSE.
The minimum record length was 1.
The maximum record length was 31.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
107
108 * libname same as fileref pointing to json content;
109 libname response json;
NOTE: JSON data is only read once. To read the JSON again, reassign the JSON LIBNAME.
NOTE: Libref RESPONSE was successfully assigned as follows:
Engine: JSON
Physical Name: C:\Users\Richard\AppData\Local\Temp\SAS Temporary
Files\_TD4224_HELIUM_\#LN00066
110
111 proc copy in=response out=work;
112 run;
NOTE: Copying RESPONSE.ALLDATA to WORK.ALLDATA (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
System Option for BUFSIZE was used.
NOTE: There were 51 observations read from the data set RESPONSE.ALLDATA.
NOTE: The data set WORK.ALLDATA has 51 observations and 4 variables.
NOTE: Copying RESPONSE.ROOT to WORK.ROOT (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set RESPONSE.ROOT.
NOTE: The data set WORK.ROOT has 1 observations and 52 variables.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
首先table复制到工作(ROOT)
我正在尝试使用来自瑞士当局的 API 从公司网络内对地址进行地理编码。我的公司使用带有用户名和密码的代理服务器。我是 SAS EG 的新手,这是我到目前为止的代码(我必须匿名化一些东西才能被允许 post 这里):
filename response temp;
options set=SSL_USE_SNI=1;
options set=SSL_SNI_HOSTNAME="api3.geo.admin.ch";
proc http
url = 'https://api3.geo.admin.ch/rest/services/api/SearchServer?searchText=Bahnhofstrasse %201%20Zürich&type=locations'
method='GET'
proxyhost = 'http://OURPROXYHOST.ch'
proxyport = 8080
proxyusername = '***'
proxypassword= '***'
out= response
ct = "application/json";
run;
然而,日志不会抛出任何错误或警告,并且当 运行 代码时我没有看到输出文件。如果我在浏览器中输入 url 就可以了。
我正在使用 SAS EG 7.15 HF7 (7.100.5.6177)(64 位)。我希望你们能在这里帮助我。
输出的headers是什么样子的,用户HEADEROUT=看看
示例代码(虽然没有代理)
filename response temp;
filename headers temp;
proc http
url = "https://worldpopulationreview.com/static/states/abbr-name.json"
method = "get"
out = response
ct = "application/json"
headerout = headers
;
data _null_;
infile headers;
input;
put _infile_;
run;
data _null_;
infile response obs=10;
input;
put _infile_;
run;
* libref name same as fileref pointing to json content;
libname response json;
proc copy in=response out=work;
run;
日志
93 headerout = headers
94 ;
95
NOTE: 200 OK
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.04 seconds
cpu time 0.00 seconds
96 data _null_;
97 infile headers;
98 input;
99 put _infile_;
100 run;
NOTE: The infile HEADERS is:
Filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD4224_HELIUM_\#LN00067,
RECFM=V,LRECL=32767,File Size (bytes)=531,
Last Modified=05Nov2020:09:39:53,
Create Time=05Nov2020:09:39:53
HTTP/1.1 200 OK
Date: Thu, 05 Nov 2020 14:39:55 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
content-disposition: inline; filename="abbr-name.json"
cache-control: public, max-age=0, must-revalidate
content-length: 1057
access-control-allow-origin: *
etag: W/"672e384a87acd2f6547e5127fde8f2fe74c991498d7b468b1e439c3860554ea8"
accept-ranges: bytes
x-vercel-cache: HIT
age: 189
server: Vercel
x-vercel-id: cle1::fz9dn-1604587195926-0957f649b2c8
strict-transport-security: max-age=63072000
NOTE: 16 records were read from the infile HEADERS.
The minimum record length was 0.
The maximum record length was 74.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
101
102 data _null_;
103 infile response obs=10;
104 input;
105 put _infile_;
106 run;
NOTE: The infile RESPONSE is:
Filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD4224_HELIUM_\#LN00066,
RECFM=V,LRECL=32767,File Size (bytes)=1057,
Last Modified=05Nov2020:09:39:53,
Create Time=05Nov2020:09:39:53
{
"AL": "Alabama",
"AK": "Alaska",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
"DC": "District Of Columbia",
NOTE: 10 records were read from the infile RESPONSE.
The minimum record length was 1.
The maximum record length was 31.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
107
108 * libname same as fileref pointing to json content;
109 libname response json;
NOTE: JSON data is only read once. To read the JSON again, reassign the JSON LIBNAME.
NOTE: Libref RESPONSE was successfully assigned as follows:
Engine: JSON
Physical Name: C:\Users\Richard\AppData\Local\Temp\SAS Temporary
Files\_TD4224_HELIUM_\#LN00066
110
111 proc copy in=response out=work;
112 run;
NOTE: Copying RESPONSE.ALLDATA to WORK.ALLDATA (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
System Option for BUFSIZE was used.
NOTE: There were 51 observations read from the data set RESPONSE.ALLDATA.
NOTE: The data set WORK.ALLDATA has 51 observations and 4 variables.
NOTE: Copying RESPONSE.ROOT to WORK.ROOT (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set RESPONSE.ROOT.
NOTE: The data set WORK.ROOT has 1 observations and 52 variables.
NOTE: PROCEDURE COPY used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
首先table复制到工作(ROOT)