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;
That is a JSON file. You can get a lot of inforamtion for googling SAS read json file:
https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/
That is a JSON file. You can get a lot of inforamtion for googling SAS read json file:
https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/
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;
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!
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.