BookmarkSubscribeRSS Feed
bkgoodwi
Calcite | Level 5

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

Obs one1
<Response
1 REPLY 1
Patrick
Opal | Level 21

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 1 reply
  • 400 views
  • 0 likes
  • 2 in conversation