<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Json output to SAS Dataset from API in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Json-output-to-SAS-Dataset-from-API/m-p/425598#M104845</link>
    <description>&lt;P&gt;What's the map/automap doing for you?&amp;nbsp; Are you wanting to control how the data values are read and convert the dates/times into proper SAS dates and times?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code reads the data as is -- all values are read in as CHAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename daily temp;
data _null_;
 file daily;
 infile datalines;
 input;
 put _infile_;
datalines;
[
{
"requestdate": "2017-12-14",
"present": "41298",
"averageouttime": " 5:09PM",
"averageintime": "10:52AM",
"registeredusers": "156495"
}
]
;
run;

libname posts JSON fileref=daily ;
proc datasets lib=posts;
run;

data result;
 set posts.root;
run;

proc print data=result; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert some of the variables to proper SAS values you can do that in DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result;
 set posts.root (rename=( requestdate=_in_requestdate ));
 /* fix the date value */
 length requestdate 8;
 format requestdate YYMMDD10.;
 requestdate = input (_in_requestdate, YYMMDD10.);
 drop _in_:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can take the generated JSON map and modify it by specifying the appropriate INFORMATs and FORMATs, &lt;A href="https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/" target="_self"&gt;as I described in this blog post&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Jan 2018 15:41:54 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2018-01-07T15:41:54Z</dc:date>
    <item>
      <title>Json output to SAS Dataset from API</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Json-output-to-SAS-Dataset-from-API/m-p/425584#M104839</link>
      <description>&lt;P&gt;I am using the below code to pull Json data directly into sas dataset from WEB API&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let url1=xyz;&lt;BR /&gt;%let url2=abc;&lt;BR /&gt;%let fullurl=&amp;amp;url1.&amp;amp;url2;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;filename minmap "/xml_data/Biometricmap.map";&lt;BR /&gt;filename daily temp;&lt;BR /&gt;&lt;BR /&gt;proc http&lt;BR /&gt;url= "&amp;amp;fullurl."&lt;BR /&gt;method="Get"&lt;BR /&gt;out=daily;&lt;BR /&gt;headers 'Content-Type' = 'application/json';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;libname posts JSON fileref=daily map=minmap automap=replace;&lt;BR /&gt;proc print data=posts.alldata(obs=20); run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not able to fetch the output Its giving me error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Logs are :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname posts JSON fileref=daily map=minmap automap=replace;&lt;BR /&gt;NOTE: JSON data is only read once. To read the JSON again, reassign the JSON LIBNAME.&lt;BR /&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt; Invalid JSON in input near line 1 column 1: Encountered an illegal character.&lt;BR /&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt; Error in the LIBNAME statement.&lt;BR /&gt;proc print data=posts.alldata(obs=20); run;&lt;BR /&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt; Libref POSTS is not assigned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this might be because the Json output contains array " [ ", can you please provide how to rectify this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output Json is :&amp;nbsp;&lt;/P&gt;&lt;P&gt;[&lt;BR /&gt;{&lt;BR /&gt;"requestdate": "2017-12-14",&lt;BR /&gt;"present": "41298",&lt;BR /&gt;"averageouttime": " 5:09PM",&lt;BR /&gt;"averageintime": "10:52AM",&lt;BR /&gt;"registeredusers": "156495"&lt;BR /&gt;}&lt;BR /&gt;]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what i want in dataset as&amp;nbsp;&lt;/P&gt;&lt;P&gt;requestdate present averageouttime averageintime registeredusers&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV&gt;2017-12-14&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV&gt;41298&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV&gt;5:09PM&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV&gt;10:52AM&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV&gt;156495&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So please help me with the correct code ??&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jan 2018 11:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Json-output-to-SAS-Dataset-from-API/m-p/425584#M104839</guid>
      <dc:creator>sizlingengg</dc:creator>
      <dc:date>2018-01-07T11:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Json output to SAS Dataset from API</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Json-output-to-SAS-Dataset-from-API/m-p/425598#M104845</link>
      <description>&lt;P&gt;What's the map/automap doing for you?&amp;nbsp; Are you wanting to control how the data values are read and convert the dates/times into proper SAS dates and times?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code reads the data as is -- all values are read in as CHAR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename daily temp;
data _null_;
 file daily;
 infile datalines;
 input;
 put _infile_;
datalines;
[
{
"requestdate": "2017-12-14",
"present": "41298",
"averageouttime": " 5:09PM",
"averageintime": "10:52AM",
"registeredusers": "156495"
}
]
;
run;

libname posts JSON fileref=daily ;
proc datasets lib=posts;
run;

data result;
 set posts.root;
run;

proc print data=result; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert some of the variables to proper SAS values you can do that in DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result;
 set posts.root (rename=( requestdate=_in_requestdate ));
 /* fix the date value */
 length requestdate 8;
 format requestdate YYMMDD10.;
 requestdate = input (_in_requestdate, YYMMDD10.);
 drop _in_:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can take the generated JSON map and modify it by specifying the appropriate INFORMATs and FORMATs, &lt;A href="https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/" target="_self"&gt;as I described in this blog post&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jan 2018 15:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Json-output-to-SAS-Dataset-from-API/m-p/425598#M104845</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-01-07T15:41:54Z</dc:date>
    </item>
  </channel>
</rss>

