<?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 Juletip #13 - Reading data from SSB using REST API and import data to SAS using Excel Ranges. in SAS Community Nordic</title>
    <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-13-Reading-data-from-SSB-using-REST-API-and-import-data/m-p/849371#M399</link>
    <description>&lt;P&gt;&lt;U&gt;Introduction:&lt;/U&gt;&lt;BR /&gt;The code is used for getting data from 2 statistics at SSB using their API and SAS proc HTTP and read the resulting Excel sheet into SAS.&lt;BR /&gt;It can be seen as SAS variant of using REST APIs, using proc http, in the same way as Python do in juletip $9&lt;/P&gt;
&lt;P&gt;The SAS code is uing proc import and RANGE in order to only read the part of the Excel sheet that is of interest. The text below is not wanted.&lt;/P&gt;
&lt;P&gt;NOTE: Due to some error somewhere, the downloaded Excel file should be opened in Excel, then just saved and Exit Excel.&lt;BR /&gt;This changes some metadata in the Excel file that makes it possible for SAS to read just parts (Range) of the excel file.&lt;/P&gt;
&lt;P&gt;The steps:&lt;BR /&gt;0. Set up filenames for proc http &lt;BR /&gt;1. To get the excel data in a folder using the SAS proc HTTP and SSB API. The URLs are gotten from SSB links above in section "API spørring.." &lt;BR /&gt;2. Read the Excel sheets into SAS, and keep the row with data&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;U&gt;How to run:&lt;/U&gt;&lt;BR /&gt;Due to the "metadata issue", the steps for running this is:&lt;BR /&gt;1. Open the program and change the location where the resulting Excel files should be saved.&lt;BR /&gt;This is the macro variable "excel_root" at the top of the program.&lt;BR /&gt;2. Run step 0 and Step 1 and make sure that 2 Excel files are produced in your location. &lt;BR /&gt;This ends at the line:&lt;BR /&gt;** STEP 2: Read the Excel sheets into SAS, and keep the row with data&lt;/P&gt;
&lt;P&gt;In the SAS log, check that the 2 proc http procedures ends with return code: NOTE: 200 OK&lt;/P&gt;
&lt;P&gt;The files are: &lt;BR /&gt;SSB_KPI.xlsx&lt;BR /&gt;SSB_KPI_Varer_Tjenester.xlsx&lt;/P&gt;
&lt;P&gt;3. Run the remaining part of the program. This creates the WORK dataset SSB_KPI and SSB_KPI_Varer_Tjenester.&lt;/P&gt;
&lt;P&gt;Things to try out:&lt;BR /&gt;- Change output in the request file from "xlsx" (excel output) to "json-stat2". For SAS proc http, look at the SAS Forum presentation "Rest just got Easy..".&lt;BR /&gt;This creates JSON output. NOTE: Now it may be useful to look at the longer SSB documentation where the short video is and Github examples.&lt;BR /&gt;NOTE that now it us useful not to download the resulting file, but let them stay in TEMP filename in SAS.&lt;BR /&gt;Adapt the Excel part to read JSON instead of Excel.&lt;BR /&gt;Adapt the columns exported in the request file&lt;BR /&gt;- Find your own API interfaces using other SSB table and adapt the program.&lt;BR /&gt;- Find other sources of REST API interfaces where the same logic can be applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The codefile "Juletip_13des2022_Read_Excel_via_SSB_API.sas" is attached and also contain some documentation.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Dec 2022 11:02:44 GMT</pubDate>
    <dc:creator>TorOveKilnesSAS</dc:creator>
    <dc:date>2022-12-13T11:02:44Z</dc:date>
    <item>
      <title>Juletip #13 - Reading data from SSB using REST API and import data to SAS using Excel Ranges.</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-13-Reading-data-from-SSB-using-REST-API-and-import-data/m-p/849371#M399</link>
      <description>&lt;P&gt;&lt;U&gt;Introduction:&lt;/U&gt;&lt;BR /&gt;The code is used for getting data from 2 statistics at SSB using their API and SAS proc HTTP and read the resulting Excel sheet into SAS.&lt;BR /&gt;It can be seen as SAS variant of using REST APIs, using proc http, in the same way as Python do in juletip $9&lt;/P&gt;
&lt;P&gt;The SAS code is uing proc import and RANGE in order to only read the part of the Excel sheet that is of interest. The text below is not wanted.&lt;/P&gt;
&lt;P&gt;NOTE: Due to some error somewhere, the downloaded Excel file should be opened in Excel, then just saved and Exit Excel.&lt;BR /&gt;This changes some metadata in the Excel file that makes it possible for SAS to read just parts (Range) of the excel file.&lt;/P&gt;
&lt;P&gt;The steps:&lt;BR /&gt;0. Set up filenames for proc http &lt;BR /&gt;1. To get the excel data in a folder using the SAS proc HTTP and SSB API. The URLs are gotten from SSB links above in section "API spørring.." &lt;BR /&gt;2. Read the Excel sheets into SAS, and keep the row with data&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;U&gt;How to run:&lt;/U&gt;&lt;BR /&gt;Due to the "metadata issue", the steps for running this is:&lt;BR /&gt;1. Open the program and change the location where the resulting Excel files should be saved.&lt;BR /&gt;This is the macro variable "excel_root" at the top of the program.&lt;BR /&gt;2. Run step 0 and Step 1 and make sure that 2 Excel files are produced in your location. &lt;BR /&gt;This ends at the line:&lt;BR /&gt;** STEP 2: Read the Excel sheets into SAS, and keep the row with data&lt;/P&gt;
&lt;P&gt;In the SAS log, check that the 2 proc http procedures ends with return code: NOTE: 200 OK&lt;/P&gt;
&lt;P&gt;The files are: &lt;BR /&gt;SSB_KPI.xlsx&lt;BR /&gt;SSB_KPI_Varer_Tjenester.xlsx&lt;/P&gt;
&lt;P&gt;3. Run the remaining part of the program. This creates the WORK dataset SSB_KPI and SSB_KPI_Varer_Tjenester.&lt;/P&gt;
&lt;P&gt;Things to try out:&lt;BR /&gt;- Change output in the request file from "xlsx" (excel output) to "json-stat2". For SAS proc http, look at the SAS Forum presentation "Rest just got Easy..".&lt;BR /&gt;This creates JSON output. NOTE: Now it may be useful to look at the longer SSB documentation where the short video is and Github examples.&lt;BR /&gt;NOTE that now it us useful not to download the resulting file, but let them stay in TEMP filename in SAS.&lt;BR /&gt;Adapt the Excel part to read JSON instead of Excel.&lt;BR /&gt;Adapt the columns exported in the request file&lt;BR /&gt;- Find your own API interfaces using other SSB table and adapt the program.&lt;BR /&gt;- Find other sources of REST API interfaces where the same logic can be applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The codefile "Juletip_13des2022_Read_Excel_via_SSB_API.sas" is attached and also contain some documentation.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 11:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-13-Reading-data-from-SSB-using-REST-API-and-import-data/m-p/849371#M399</guid>
      <dc:creator>TorOveKilnesSAS</dc:creator>
      <dc:date>2022-12-13T11:02:44Z</dc:date>
    </item>
  </channel>
</rss>

