DATA Step, Macro, Functions and more

put _infile_ data into a sas dataset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

put _infile_ data into a sas dataset

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;

Accepted Solutions
Solution
‎01-09-2018 03:07 AM
Super User
Super User
Posts: 9,198

Re: put _infile_ data into a sas dataset


All Replies
Solution
‎01-09-2018 03:07 AM
Super User
Super User
Posts: 9,198

Re: put _infile_ data into a sas dataset

Super User
Posts: 9,559

Re: put _infile_ data into a sas dataset

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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 157 views
  • 0 likes
  • 3 in conversation