<?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: Read in XLS files without PROC IMPORT or XLSX engine in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874178#M345357</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;Since I don't know what your data look like, so I created 2 excel files (havenum, havechar- X is defined as num and char ),&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;please see attached files.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;Methods:&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1. One of the approach is to convert excel files to CSV files-&lt;CODE class=" language-sas"&gt;select CSV UTF-8(Comma Delimited).&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; then use PRO IMPORT. (Method 1 in the SAS code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; You may need to find a way to convert xls to CSV by using VBA code for a batch conversion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. To use ALLCHAR for &lt;SPAN&gt;SAS 9.4M5&lt;/SPAN&gt;&amp;nbsp;users (Method 2 in the SAS code)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*STEP1: Save the xls file to CSV file
         To convert Excel to CSV file without losing data,
         first, navigate to File and click on Save As. 
         From the Save As type dropdown, select CSV UTF-8(Comma Delimited). Click on Save. 
         This saves the CSV file without losing any characters*/

/*STEP2: proc import ,dbms=csv ,text file 
         Note: there is a new option but only available for SAS9.4, &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm*/" target="_blank"&gt;
		https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm*/
&lt;/A&gt;&lt;BR /&gt;/* METHOD 1 */
PROC IMPORT OUT= havechar
DATAFILE="C:\havechar.csv"
DBMS=CSV
REPLACE;
guessingrows=33333; 
GETNAMES=YES; 
run;
 
PROC IMPORT OUT= havenum
DATAFILE="C:\havenum.csv"
DBMS=CSV
REPLACE;
guessingrows=3333; 
GETNAMES=YES; 
run;

/* METHOD 2 */
%let EFI_ALLCHARS=YES;

PROC IMPORT OUT= m2havechar
DATAFILE="C:\havechar.xlsx"
DBMS=xlsx; 
run;
 
PROC IMPORT OUT= m2havenumm
DATAFILE="C:\havenum.xlsx"
DBMS=xlsx;
run;
%let EFI_ALLCHARS=no;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#800000"&gt;Output:&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: It seems that Method 2 successfully keep the original format for characters- see the difference between yellow vs blue cell.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Method 1&lt;FONT color="#FFFF00"&gt; (Yellow),&lt;/FONT&gt; X are aligned right , but Method 2&lt;FONT color="#0000FF"&gt;(Blue)&lt;/FONT&gt; keeps the blanks&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="purpleclothlady_1-1683305527153.png" style="width: 693px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83654i743355A652E05779/image-dimensions/693x349?v=v2" width="693" height="349" role="button" title="purpleclothlady_1-1683305527153.png" alt="purpleclothlady_1-1683305527153.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;Reference Post:&amp;nbsp; allchar option&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#000000"&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/PROC-IMPORT-all-fields-as-character/idi-p/278415#M2011" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/PROC-IMPORT-all-fields-as-character/idi-p/278415#M2011&lt;/A&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#000000"&gt;Add an ALLCHAR option to the PROC IMPORT statement -- to import all variables as character.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;This should apply to external text files and to Excel files&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;(considering CSV files to be text files)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;SAS document:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best wish,&lt;/P&gt;
&lt;P&gt;purple&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2023 16:56:23 GMT</pubDate>
    <dc:creator>purpleclothlady</dc:creator>
    <dc:date>2023-05-05T16:56:23Z</dc:date>
    <item>
      <title>Read in XLS files without PROC IMPORT or XLSX engine</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874150#M345348</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to read in just the first row of 100+ XLS files (to get the list of var names).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC IMPORT will not work because the data are very messy and it would take too long to sort through (when I try this I get a lot of, X variable has been defined as both char and numeric).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;XLSX engine not a good bet because each of the 100+ files has a distinct sheet name and there's no way to impute it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I have so far. It reads in the first row of each file with no bad log messages, but the text is nonsense:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data pre_process_&amp;amp;i.;&lt;BR /&gt;&lt;BR /&gt;infile "&amp;amp;&amp;amp;fnm&amp;amp;i.."&lt;BR /&gt;delimiter=',' missover dsd lrecl=32767 firstobs=1 obs=1;&lt;BR /&gt;&lt;BR /&gt;informat &lt;BR /&gt;header1 $2500.&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;input&lt;BR /&gt;header1 $&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 14:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874150#M345348</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2023-05-05T14:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Read in XLS files without PROC IMPORT or XLSX engine</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874159#M345351</link>
      <description>&lt;P&gt;Do you have actual XLSX files?&lt;/P&gt;
&lt;P&gt;Or do you have files that are instead using the ancient XLS format instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have actual XLS files so any of the files have multiple worksheets?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so you will need to use some other tool to convert the sheets into something that SAS can read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have XLSX files then the XLSX libref engine will let you get the column headers.&amp;nbsp; Whether or not the variables get defined as the same type does not impact the value of the column headers.&amp;nbsp; So if the variable types matter then you have a different issue than what you question says.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 15:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874159#M345351</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-05T15:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Read in XLS files without PROC IMPORT or XLSX engine</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874163#M345352</link>
      <description>&lt;P&gt;They are actually XLS files.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They have sheet NAMES (as opposed to Sheet1) but each one only has a single sheet, so if there is some workaround there, let me know.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 15:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874163#M345352</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2023-05-05T15:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Read in XLS files without PROC IMPORT or XLSX engine</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874165#M345353</link>
      <description>&lt;P&gt;If they only have one sheet then just use proc import.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='file1.xls' dbms=xls out=dummy replace;
run;
proc contents data=dummy noprint out=contents;
run;
proc print data=contents;
  var varnum name label;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To aggregate the names over multiple XLS files you could make a macro that takes as input the filename and appends each new file to base table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xls_vars(filename);
proc import datafile=&amp;amp;filename dbms=xls out=dummy replace;
run;
proc contents data=dummy noprint out=contents;
run;
data this_file;
  length filename $200 ;
  filename=&amp;amp;filename;
  set contents(keep=varnum name label);
run;
proc append base=all_files data=this_file force;
run;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then call it once for each XLS file.&lt;/P&gt;
&lt;P&gt;So if you have a dataset name FILES with a variable named FILENAME that has the list of XLS files you want read you could run this step to call the macro once for each file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set files;
  call execute(cats('%nrstr(%xls_vars)(',quote(trim(filename),"'"),')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 15:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874165#M345353</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-05T15:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Read in XLS files without PROC IMPORT or XLSX engine</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874178#M345357</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;Since I don't know what your data look like, so I created 2 excel files (havenum, havechar- X is defined as num and char ),&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;please see attached files.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;Methods:&lt;/FONT&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1. One of the approach is to convert excel files to CSV files-&lt;CODE class=" language-sas"&gt;select CSV UTF-8(Comma Delimited).&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; then use PRO IMPORT. (Method 1 in the SAS code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; You may need to find a way to convert xls to CSV by using VBA code for a batch conversion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. To use ALLCHAR for &lt;SPAN&gt;SAS 9.4M5&lt;/SPAN&gt;&amp;nbsp;users (Method 2 in the SAS code)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*STEP1: Save the xls file to CSV file
         To convert Excel to CSV file without losing data,
         first, navigate to File and click on Save As. 
         From the Save As type dropdown, select CSV UTF-8(Comma Delimited). Click on Save. 
         This saves the CSV file without losing any characters*/

/*STEP2: proc import ,dbms=csv ,text file 
         Note: there is a new option but only available for SAS9.4, &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm*/" target="_blank"&gt;
		https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm*/
&lt;/A&gt;&lt;BR /&gt;/* METHOD 1 */
PROC IMPORT OUT= havechar
DATAFILE="C:\havechar.csv"
DBMS=CSV
REPLACE;
guessingrows=33333; 
GETNAMES=YES; 
run;
 
PROC IMPORT OUT= havenum
DATAFILE="C:\havenum.csv"
DBMS=CSV
REPLACE;
guessingrows=3333; 
GETNAMES=YES; 
run;

/* METHOD 2 */
%let EFI_ALLCHARS=YES;

PROC IMPORT OUT= m2havechar
DATAFILE="C:\havechar.xlsx"
DBMS=xlsx; 
run;
 
PROC IMPORT OUT= m2havenumm
DATAFILE="C:\havenum.xlsx"
DBMS=xlsx;
run;
%let EFI_ALLCHARS=no;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#800000"&gt;Output:&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: It seems that Method 2 successfully keep the original format for characters- see the difference between yellow vs blue cell.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Method 1&lt;FONT color="#FFFF00"&gt; (Yellow),&lt;/FONT&gt; X are aligned right , but Method 2&lt;FONT color="#0000FF"&gt;(Blue)&lt;/FONT&gt; keeps the blanks&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="purpleclothlady_1-1683305527153.png" style="width: 693px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83654i743355A652E05779/image-dimensions/693x349?v=v2" width="693" height="349" role="button" title="purpleclothlady_1-1683305527153.png" alt="purpleclothlady_1-1683305527153.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;Reference Post:&amp;nbsp; allchar option&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#000000"&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/PROC-IMPORT-all-fields-as-character/idi-p/278415#M2011" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/PROC-IMPORT-all-fields-as-character/idi-p/278415#M2011&lt;/A&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#000000"&gt;Add an ALLCHAR option to the PROC IMPORT statement -- to import all variables as character.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;This should apply to external text files and to Excel files&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;(considering CSV files to be text files)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;SAS document:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p12uk352fte2h1n1efh4r44dmxmp.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;best wish,&lt;/P&gt;
&lt;P&gt;purple&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 16:56:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-XLS-files-without-PROC-IMPORT-or-XLSX-engine/m-p/874178#M345357</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2023-05-05T16:56:23Z</dc:date>
    </item>
  </channel>
</rss>

