<?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 Importing table with unknown length from Excel xlsm to SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229249#M41468</link>
    <description>&lt;P&gt;I want to transfer a table from Excel to SAS (My SAS version is 9.2 and Excel file format is XLSM, macro). The column names will be read from the cell B3 and the data will start from the cell B4, like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;  A   B   C   D   E   F   G ...
1
2
3   Col1 Col2 
4    15   20
5    16   21
6    ... ...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that the last row number is unknown, because the table length can be 200 rows today and it can be 350 rows tomorrow. So how can I import this table from Excel (XLSM) to SAS-table?&lt;/P&gt;
&lt;P&gt;I read in somwhere that we can use &lt;CODE&gt;DATAROW&lt;/CODE&gt; in &lt;CODE&gt;Proc Import&lt;/CODE&gt; when &lt;CODE&gt;DBMS=EXCEL&lt;/CODE&gt; like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;proc import datafile = "!datafile" out=Table1 DBMS = EXCEL REPLACE; 
    SHEET = "Sheet1"; GETNAMES=YES; MIXED=YES; USEDATE=YES; SCANTIME=YES; NAMEROW=3; DATAROW=4;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, SAS can not recognize the &lt;CODE&gt;DATAROW&lt;/CODE&gt; option, giving the error &lt;CODE&gt;ERROR 180-322: Statement is not valid or it is used out of proper order. &lt;/CODE&gt;. There is another way of importing table from Excel like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;PROC SQL;
  CONNECT TO EXCEL            (PATH='C:\\thepath\excelfile.xlsm');
  Create Table Table1 as SELECT * FROM CONNECTION TO EXCEL 
  (SELECT * FROM [Sheet1$]);
  DISCONNECT FROM EXCEL;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As a result, does anyone know how to export a table with Unknown rows from XLSM to SAS? Thanks in advance...&lt;/P&gt;</description>
    <pubDate>Fri, 09 Oct 2015 11:30:14 GMT</pubDate>
    <dc:creator>cercig</dc:creator>
    <dc:date>2015-10-09T11:30:14Z</dc:date>
    <item>
      <title>Importing table with unknown length from Excel xlsm to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229249#M41468</link>
      <description>&lt;P&gt;I want to transfer a table from Excel to SAS (My SAS version is 9.2 and Excel file format is XLSM, macro). The column names will be read from the cell B3 and the data will start from the cell B4, like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;  A   B   C   D   E   F   G ...
1
2
3   Col1 Col2 
4    15   20
5    16   21
6    ... ...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem is that the last row number is unknown, because the table length can be 200 rows today and it can be 350 rows tomorrow. So how can I import this table from Excel (XLSM) to SAS-table?&lt;/P&gt;
&lt;P&gt;I read in somwhere that we can use &lt;CODE&gt;DATAROW&lt;/CODE&gt; in &lt;CODE&gt;Proc Import&lt;/CODE&gt; when &lt;CODE&gt;DBMS=EXCEL&lt;/CODE&gt; like below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;proc import datafile = "!datafile" out=Table1 DBMS = EXCEL REPLACE; 
    SHEET = "Sheet1"; GETNAMES=YES; MIXED=YES; USEDATE=YES; SCANTIME=YES; NAMEROW=3; DATAROW=4;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, SAS can not recognize the &lt;CODE&gt;DATAROW&lt;/CODE&gt; option, giving the error &lt;CODE&gt;ERROR 180-322: Statement is not valid or it is used out of proper order. &lt;/CODE&gt;. There is another way of importing table from Excel like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;PROC SQL;
  CONNECT TO EXCEL            (PATH='C:\\thepath\excelfile.xlsm');
  Create Table Table1 as SELECT * FROM CONNECTION TO EXCEL 
  (SELECT * FROM [Sheet1$]);
  DISCONNECT FROM EXCEL;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As a result, does anyone know how to export a table with Unknown rows from XLSM to SAS? Thanks in advance...&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 11:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229249#M41468</guid>
      <dc:creator>cercig</dc:creator>
      <dc:date>2015-10-09T11:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Importing table with unknown length from Excel xlsm to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229267#M41477</link>
      <description>&lt;P&gt;To be honest going from Excel (unstrcutured mess) to SAS (structured format) is going to be difficult. &amp;nbsp;You could try specifyfing the range as A:Z and drop blank records. &amp;nbsp;However, do the columns all have the same format in each observations etc. &amp;nbsp;Why can you not just remove those two records from the start. &amp;nbsp;If it was me I would write a small VBA macro which just runs over the range, i.e. A4: xlRight/xlDown, and loop over the data writing out a CSV file.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/22618513/vba-looping-through-range-writing-to-csv" target="_blank"&gt;http://stackoverflow.com/questions/22618513/vba-looping-through-range-writing-to-csv&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can simply import the CSV into SAS using datastep and infile.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 12:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229267#M41477</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T12:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Importing table with unknown length from Excel xlsm to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229268#M41478</link>
      <description>&lt;P&gt;First of all, save the file in a suitable file transfer format (which xlsm is NOT), ie csv.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.88px; line-height: 18.4px;"&gt;The DATAROW statement is valid only for delimited files, so it cannot be used with crappy formats like the xlsX family.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.88px; line-height: 18.4px;"&gt;(This is explicitly explained in the PROC IMPORT documentation)&lt;/SPAN&gt;&lt;SPAN style="font-size: 12.88px; line-height: 18.4px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 12:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229268#M41478</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-10-09T12:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Importing table with unknown length from Excel xlsm to SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229284#M41485</link>
      <description>&lt;P&gt;I found an "ineffective" alternative solution which reads all possible rows in Excel (reads 50.000 rows), at the same time it checks every row under the column &lt;CODE&gt;Col1&lt;/CODE&gt; if these rows have a value.&lt;/P&gt;
&lt;P&gt;It takes 7-8 seconds, and it works. But as I wrote, it feels ineffective to read the whole 50.000 rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;PROC SQL;
   CONNECT TO EXCEL            (PATH='C:\\thepath\excelfile.xlsm');
   Create Table Table1 as SELECT * FROM CONNECTION TO EXCEL 
   (SELECT * FROM [Sheet1$B3:C50000] WHERE Col1 IS NOT NULL);
   DISCONNECT FROM EXCEL;
QUIT;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 13:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-table-with-unknown-length-from-Excel-xlsm-to-SAS/m-p/229284#M41485</guid>
      <dc:creator>cercig</dc:creator>
      <dc:date>2015-10-09T13:39:10Z</dc:date>
    </item>
  </channel>
</rss>

