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 🙂 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1545 views
  • 1 like
  • 2 in conversation