Have exhausted a day trying to extract data that a FCC API returns as xml. The data pull works correctly but I find it impossible to get the data into SAS. I have tried using XML libref as well as trying to read as text. If I read as text and use formats, it will only return first 8 characters when I use proc print. Any hints would be greatly appreciated. Here is the code:
FILENAME ex "f:/prf/Example.xml";
proc http url='https://geo.fcc.gov/api/census/block/find?latitude=35&longitude=-100&format=xml' /* The base URL */
method="GET" /* HTTP method used for request */
out=ex;
run;
data fips; infile ex;
length one $ 212;informat one $212.;format one $212.;
input one $;
put _infile_;
run;
proc contents;
proc print; run;
Which returns
The SAS System |
<Response |
Below works for me.
FILENAME response temp;
proc http url='https://geo.fcc.gov/api/census/block/find?latitude=35&longitude=-100&format=xml' /* The base URL */
method="GET" /* HTTP method used for request */
out=response;
run;
/* write response xml to SAS log */
data _null_;
infile response end=last;
input;
put _infile_;
run;
/* read response xml into SAS data sets */
/* https://go.documentation.sas.com/?docsetId=engxml&docsetTarget=p03yh3krbywig1n1v6lgkuwb3csa.htm&docsetVersion=9.4&locale=en */
filename respmap temp;
libname response xmlv2 automap=replace xmlmap=respmap;
proc contents data=response._all_;
run;
proc print data=response.county;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: