<?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: Appending latest observation with PROC HTTP and JSON library in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516935#M73291</link>
    <description>&lt;P&gt;Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the great code. I worked with my permanent libraries and eventually got everything worked out. I have been bouncing between SAS Studio and running it as crontab via a shell script, but it looks like I have the crontab working correctly. Cleaning up the JSON labels was my next step, so I appreciate you getting me there a lot faster.. I did end up using an Append statement, rather than the Data/Step. Enjoyed you snackbot post!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Nov 2018 02:40:38 GMT</pubDate>
    <dc:creator>DWhite</dc:creator>
    <dc:date>2018-11-29T02:40:38Z</dc:date>
    <item>
      <title>Appending latest observation with PROC HTTP and JSON library</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516520#M73268</link>
      <description>&lt;P&gt;Hello. I am calling an API from a simple sensor reporting a couple of variables. The API presents the latest observation. I am able to successfully process the latest observation. I want to repeatedly call the API with a crontab to build a historical data set including the latest observation. The code below is how I am approaching this (for original source see: &lt;A href="https://blogs.sas.com/content/sasdummy/2018/07/02/snackbot-api-timeseries/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2018/07/02/snackbot-api-timeseries/&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting stuck on the append. I have tried Proc Append, and a DATA/SET statement (using below), but I am missing something. The "sensor_readings" table is always overwritten with the latest observation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
/* Call the API */
filename feeds temp;
proc http
  method="GET"
  url="https://api.thingspeak.com/channels/622255/feeds.json?results=2"
  out=feeds;
run;
 
/* JSON libname engine to read the result       */
libname sensor json fileref=feeds;
data sensor_readings;
  set sensor.feeds;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 23:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516520#M73268</guid>
      <dc:creator>DWhite</dc:creator>
      <dc:date>2018-11-27T23:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Appending latest observation with PROC HTTP and JSON library</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516523#M73269</link>
      <description>&lt;P&gt;instead of data step can you try proc append.&amp;nbsp; datastep overwrites your previous dataset with same name.&lt;/P&gt;
&lt;P&gt;perm in below example is to use some permanent library which is available to you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;proc append base= perm.sensor_readings  data=sensor.feeds;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 23:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516523#M73269</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-27T23:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Appending latest observation with PROC HTTP and JSON library</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516678#M73274</link>
      <description>&lt;P&gt;Sounds like a fun project!&amp;nbsp; Because your API call works with a public site, I was able to try some things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, you might consider converting the values you read into proper SAS numerics -- will be easier to analyze trends, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can create a "template" data set for storing the records, and append this with either PROC APPEND or with DATA step SET statements -- taking care to add to, not simply replace, the existing data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Call the API */
filename feeds temp;
proc http
  method="GET"
  url="https://api.thingspeak.com/channels/622255/feeds.json?results=2"
  out=feeds;
run;

/* assign this to a real permanent location */
libname perm (WORK); 

/* do this once to create a template for your data */
data perm.watt_sensor;
 length luminosity 8
        temperature 8
        created_at 8
        entry_id 8;
 format created_at datetime20.;
 stop;
run;

/* JSON libname engine to read the result       */
/* Prep just records with new readings          */
libname sensor json fileref=feeds;
data new_readings;
 set sensor.feeds (rename=(created_at=created_at_char));
 length luminosity 8
        temperature 8
        created_at 8
        entry_id 8;
  format created_at datetime20.;
  
  created_at = input(created_at_char,anydtdtm.);
  luminosity = input(compress(field1,'.','kd'),10.);
  temperature = input(compress(field2,'.','kd'),10.2);
  
  drop field: created_at_char ordinal:;
run;

/* or use PROC APPEND */
data perm.watt_sensor;
 set perm.watt_sensor 
     new_readings;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 14:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516678#M73274</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-11-28T14:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Appending latest observation with PROC HTTP and JSON library</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516932#M73289</link>
      <description>&lt;P&gt;Kiranv_, The append did work. Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 02:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516932#M73289</guid>
      <dc:creator>DWhite</dc:creator>
      <dc:date>2018-11-29T02:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Appending latest observation with PROC HTTP and JSON library</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516935#M73291</link>
      <description>&lt;P&gt;Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the great code. I worked with my permanent libraries and eventually got everything worked out. I have been bouncing between SAS Studio and running it as crontab via a shell script, but it looks like I have the crontab working correctly. Cleaning up the JSON labels was my next step, so I appreciate you getting me there a lot faster.. I did end up using an Append statement, rather than the Data/Step. Enjoyed you snackbot post!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Nov 2018 02:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Appending-latest-observation-with-PROC-HTTP-and-JSON-library/m-p/516935#M73291</guid>
      <dc:creator>DWhite</dc:creator>
      <dc:date>2018-11-29T02:40:38Z</dc:date>
    </item>
  </channel>
</rss>

