BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ebowen
Quartz | Level 8

Hello! I'm trying to access some Census data using their API, and I'm having a problem getting the proper field names. I'm able to download the data, but the field names end up as the first observation in the dataset. When I look at the API itself, the field names are listed as the "0" observation. I can't figure out how to get SAS to recognize that the first observation is actually the field names. Here's my code so far:

 

filename cns temp;
proc http
   url='https://api.census.gov/data/2017/acs/acs5?get=NAME,group(B23025)&for=county:*'
   method= "GET"
   out=cns;
run;
libname census JSON fileref=cns;

Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Looks like they just wrapped a CSV file into json like syntax.

Why not just reverse the process?

filename csv temp;
data _null_;
  set census.root;
  file csv dsd ;
  put (_all_) (+0);
run;
proc import datafile=csv dbms=csv out=census replace;
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Looks like they just wrapped a CSV file into json like syntax.

Why not just reverse the process?

filename csv temp;
data _null_;
  set census.root;
  file csv dsd ;
  put (_all_) (+0);
run;
proc import datafile=csv dbms=csv out=census replace;
run;
ebowen
Quartz | Level 8

So the Census doesn't have properly formed JSON code. Somehow I'm not surprised.

 

EDIT: I just found this on the Census API Developer page: "The Census uses a nonstandard version of JSON that is streamlined."

Tom
Super User Tom
Super User

Reminds of a story from when everyone was insisting that data transfers had to use XML.  For an existing system that was using CSV to transfer the files they just wrapped that CSV file as CDATA object in an XML. Problem solved 🙂 

 

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
  • 3 replies
  • 1307 views
  • 1 like
  • 2 in conversation