<?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: Using API for CSV data in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/533123#M7644</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259569"&gt;@postollma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I run the previously posted code then a file gets created with content:&lt;/P&gt;
&lt;PRE&gt;Invalid API key. Please see the &amp;lt;a href="/dataset/api"&amp;gt;API Help&amp;lt;/a&amp;gt; (https://www.tycho.pitt.edu/dataset/api) for more information.&lt;/PRE&gt;
&lt;P&gt;Do you get the same when running the code with the invalid API key? And what happens if you use a valid API key? AND: What does the SAS log tell you?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Feb 2019 03:31:39 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-02-06T03:31:39Z</dc:date>
    <item>
      <title>Using API for CSV data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/532319#M7639</link>
      <description>&lt;P&gt;I am trying to download data that is in a CSV format from a query on the project tycho website.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename response temp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc http&lt;BR /&gt;url="&lt;A href="https://www.tycho.pitt.edu/api/query?apikey=MYAPIKEYHERE&amp;amp;ConditionName=Measles&amp;amp;CountryISO=US" target="_blank" rel="noopener"&gt;https://www.tycho.pitt.edu/api/query?apikey=MYAPIKEYHERE&amp;amp;ConditionName=Measles&amp;amp;CountryISO=US&lt;/A&gt;"&lt;BR /&gt;out=response;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen answers to other similar questions that show how to do the next step (libname statement) with JSON formats, but not with CSV. Does anyone know how to do this?&lt;/P&gt;&lt;P&gt;Also, this is the first time I have worked with APIs. After the CSV is imported, do I just continue to analyze the data with data steps and procedures? Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 21:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/532319#M7639</guid>
      <dc:creator>postollma</dc:creator>
      <dc:date>2019-02-02T21:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using API for CSV data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/532341#M7640</link>
      <description>&lt;P&gt;Your URL must either be in single quotes or within %NRSTR() for SAS not interpreting the &amp;amp; as SAS macro tokens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename response temp;
proc http
  url=%nrstr("https://www.tycho.pitt.edu/api/query?apikey=MYAPIKEYHERE&amp;amp;ConditionName=Measles&amp;amp;CountryISO=US")
  out=response;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FILENAME RESPONSE TEMP;&lt;/P&gt;
&lt;P&gt;will write whatever you download into a file on disk stored in the SAS WORK location. The file is temporary in the sense that the WORK location gets deleted when terminating a SAS session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know that what you're downloading is a .csv then you could for development purposes write this file to another location than SAS WORK. To do so you simply need to change your filename statement to something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;FILENAME RESPONSE "&amp;lt;folder path accessible to where SAS executes&amp;gt;\myfile.csv";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you can easily access the file and inspect its content. Next step will be to read the external data into SAS. It it's a .csv the either use PROC IMPORT or even better use a SAS Datastep.&lt;/P&gt;
&lt;P&gt;What I'm normally doing with text files like a .csv when SAS EG is available:&lt;/P&gt;
&lt;P&gt;1. download the file to my local disk&lt;/P&gt;
&lt;P&gt;2. use the SAS import wizard to generate the import code (but you can also use the code Proc Import generates)&lt;/P&gt;
&lt;P&gt;3. modify the code to my final solution (i.e. change lengths and informats)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once done with development point your filename back to TEMP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...and if you just want to quickly see in the log what you're downloading then code as below should do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options ls=max ps=max;
filename response temp lrecl=100000;
proc http
  url=%nrstr("https://www.tycho.pitt.edu/api/query?apikey=MYAPIKEYHERE&amp;amp;ConditionName=Measles&amp;amp;CountryISO=US")
  out=response;
run;
data _null_;
  infile response;
  input;
  put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Feb 2019 04:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/532341#M7640</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-03T04:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using API for CSV data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/533027#M7643</link>
      <description>&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using single quotes and the %nrstr() options, but the file doesn't show up in the work folder.&lt;/P&gt;&lt;P&gt;I also tried saving to my documents folder instead of temp, but the file doesn't show up there either.&lt;/P&gt;&lt;P&gt;Any thoughts on what is going wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 18:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/533027#M7643</guid>
      <dc:creator>postollma</dc:creator>
      <dc:date>2019-02-05T18:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using API for CSV data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/533123#M7644</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259569"&gt;@postollma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I run the previously posted code then a file gets created with content:&lt;/P&gt;
&lt;PRE&gt;Invalid API key. Please see the &amp;lt;a href="/dataset/api"&amp;gt;API Help&amp;lt;/a&amp;gt; (https://www.tycho.pitt.edu/dataset/api) for more information.&lt;/PRE&gt;
&lt;P&gt;Do you get the same when running the code with the invalid API key? And what happens if you use a valid API key? AND: What does the SAS log tell you?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 03:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/533123#M7644</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-06T03:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using API for CSV data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/533228#M7647</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Try this url with my APIKEY&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.tycho.pitt.edu/api/query?apikey=056b7aa4c98a061c4136&amp;amp;ConditionName=Measles&amp;amp;CountryISO=US" target="_blank" rel="noopener"&gt;https://www.tycho.pitt.edu/api/query?apikey=056b7aa4c98a061c4136&amp;amp;ConditionName=Measles&amp;amp;CountryISO=US&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After I have this run, the log says "PROCEDURE HTTP used" then gives me the real and cpu processing times.&lt;/P&gt;&lt;P&gt;It also has a note that says "200 OK"&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 15:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/533228#M7647</guid>
      <dc:creator>postollma</dc:creator>
      <dc:date>2019-02-19T15:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using API for CSV data</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/536897#M7663</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259569"&gt;@postollma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry for answering so late. Below code works for me.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options ls=max ps=max;
filename response temp lrecl=100000;
proc http
  url='https://www.tycho.pitt.edu/api/query?apikey=056b7aa4c98a061c4136&amp;amp;ConditionName=Measles&amp;amp;CountryISO=US'
  out=response;
run;
data _null_;
  infile response;
  input;
  put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Feb 2019 20:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Using-API-for-CSV-data/m-p/536897#M7663</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-19T20:13:58Z</dc:date>
    </item>
  </channel>
</rss>

