<?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: import excel by defining type of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790140#M252941</link>
    <description>&lt;P&gt;The approach taken in &lt;A href="https://datacontroller.io" target="_self"&gt;Data Controller&lt;/A&gt; is to take the variable types (numeric, character, dates, datetimes, times, precision, lengths, etc) from the target table that you are trying to load.&amp;nbsp; Excel is parsed in the browser (using an OEM version of &lt;A href="https://github.com/SheetJS/sheetjs" target="_self"&gt;sheetjs&lt;/A&gt;) and then - after validations - sent to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very basic / simple example of this can be found in the following macro, which could surely be adapted for excel:&amp;nbsp;&amp;nbsp;&lt;A href="https://core.sasjs.io/mp__csv2ds_8sas.html" target="_blank" rel="noopener"&gt;https://core.sasjs.io/mp__csv2ds_8sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea of reading the types from Excel sounds nice in theory but is very shaky in practice.&amp;nbsp; A column could contain all numerics, but in fact be a character field (eg with leading zeros).&lt;BR /&gt;&lt;BR /&gt;A column could contain single alphabetical characters ($1) but in fact be fully populated with special SAS missing numerics.&lt;BR /&gt;&lt;BR /&gt;A column could be empty, in which case is it character or numeric?&lt;BR /&gt;&lt;BR /&gt;Far better to have a template in mind, where possible...&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 14:27:24 GMT</pubDate>
    <dc:creator>AllanBowe</dc:creator>
    <dc:date>2022-01-14T14:27:24Z</dc:date>
    <item>
      <title>import excel by defining type of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790135#M252938</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;To read excel file i usually use proc import. But in this case, i want to define type of variables and length during the reading of excel file. Of course proc import cannot do that. Maybe there are another way or procedure i can do that.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 14:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790135#M252938</guid>
      <dc:creator>AlexeyS</dc:creator>
      <dc:date>2022-01-14T14:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: import excel by defining type of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790137#M252939</link>
      <description>&lt;P&gt;When reading Excel files with PROC IMPORT or LIBNAME XLSX, the data types and lengths are taken from the cues SAS reads from the Excel file. If you want more control over the final output, it usually requires a second step (DATA step, PROC SQL, or PROC DATASETS) to change/transform the way variables are stored and their metadata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Others on this forum will (rightly) say that reading CSV gives you much more flexibility on the input process. But...we are given what we are given and if an Excel file is the input, it can be a little work to add the rigorous structures we require for downstream analysis and reporting in SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 14:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790137#M252939</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2022-01-14T14:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: import excel by defining type of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790140#M252941</link>
      <description>&lt;P&gt;The approach taken in &lt;A href="https://datacontroller.io" target="_self"&gt;Data Controller&lt;/A&gt; is to take the variable types (numeric, character, dates, datetimes, times, precision, lengths, etc) from the target table that you are trying to load.&amp;nbsp; Excel is parsed in the browser (using an OEM version of &lt;A href="https://github.com/SheetJS/sheetjs" target="_self"&gt;sheetjs&lt;/A&gt;) and then - after validations - sent to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very basic / simple example of this can be found in the following macro, which could surely be adapted for excel:&amp;nbsp;&amp;nbsp;&lt;A href="https://core.sasjs.io/mp__csv2ds_8sas.html" target="_blank" rel="noopener"&gt;https://core.sasjs.io/mp__csv2ds_8sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea of reading the types from Excel sounds nice in theory but is very shaky in practice.&amp;nbsp; A column could contain all numerics, but in fact be a character field (eg with leading zeros).&lt;BR /&gt;&lt;BR /&gt;A column could contain single alphabetical characters ($1) but in fact be fully populated with special SAS missing numerics.&lt;BR /&gt;&lt;BR /&gt;A column could be empty, in which case is it character or numeric?&lt;BR /&gt;&lt;BR /&gt;Far better to have a template in mind, where possible...&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 14:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790140#M252941</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-01-14T14:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: import excel by defining type of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790141#M252942</link>
      <description>&lt;P&gt;Since Allan chimed in about how DataController does it, I'll add that SAS Enterprise Guide takes a similar approach. The Import Data task in &lt;A href="https://blogs.sas.com/content/sasdummy/2011/05/18/behind-the-scenes-importing-excel-files-using-sas-enterprise-guide/" target="_self"&gt;SAS Enterprise Guide will read the Excel file metadata&lt;/A&gt; and present you with all of the options to select columns you want, types, formats, lengths, etc. Then the task will read the Excel file and convert to text, sending to SAS to import like a CSV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are okay with a client-side process that reads the Excel file first and sends it to SAS, then SAS Enterprise Guide or a tool like DataController can serve. However, many people need a process that can run 100% repeatable in SAS code.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 14:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-excel-by-defining-type-of-variables/m-p/790141#M252942</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2022-01-14T14:33:14Z</dc:date>
    </item>
  </channel>
</rss>

