BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rudfaden
Lapis Lazuli | Level 10

I am reading data from an API. I get the following response 

 

 

[
{
  "id": "0a3f50a4-dea6-32b8-e044-0003ba298018",
  "status": 1,
  "vejkode": "1723",
  "vejnavn": "**bleep**otvej",
  "adresseringsvejnavn": "**bleep**otvej",
  "husnr": "70",
  "etage": null,
  "dør": null,
  "supplerendebynavn": null,
  "postnr": "2730",
  "postnrnavn": "Herlev",
  "kommunekode": "0163",
  "adgangsadresseid": "0a3f507c-788b-32b8-e044-0003ba298018",
  "x": 12.43946822,
  "y": 55.7150554
}
]

Is there a easy way to convert this to a sas data set?

 

 

Minimal working example below.

 

filename src temp;
proc http
 method="GET"
 url='https://dawa.aws.dk/adresser?vejnavn=**bleep**otvej&husnr=70&postnr=2730&struktur=mini'
 out=src;
run;


data test2;
   infile src;
   input ;

   put _infile_;
run;
1 ACCEPTED SOLUTION
2 REPLIES 2
Kurt_Bremser
Super User

And if you're not at the required maintenance level for the JSON libname engine already, this code (after expansion of the select() block) will also do it:

data test2;
infile src truncover;
length input_line $100;
length
  id $36
  status 3
  veikode $4
  vejnavn $20
  adresseringsvejnavn $20
  husnr $10
  etage $10
  door $10
  supplerendebynavn $10
  postnr $4
  postnrnavn $20
  kommunekode $4
  adgangsadresseid $36
  x y 8
;
retain
  id
  status
  veikode
  vejnavn
  adresseringsvejnavn
  husnr
  etage
  door
  supplerendebynavn
  postnr
  postnrnavn
  kommunekode
  adgangsadresseid
  x y 
;
input input_line $100.;
select (compress(scan(input_line,1,':'),'"'));
  when ('{','}');
  when ('[') do;
    id = "";
    status = .;
    veikode = "";
    vejnavn = "";
    adresseringsvejnavn = "";
    husnr = "";
    etage = "";
    door = "";
    supplerendebynavn = "";
    postnr = "";
    postnrnavn = "";
    kommunekode = "";
    adgangsadresseid = "";
    x = .;
    y = .;
  end;
  when (']') output;
  when ('id') id = compress(scan(input_line,2,':'),'"');
  otherwise;
end;
drop input_line;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1102 views
  • 0 likes
  • 3 in conversation