I want to transfer a table from Excel to 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:
A B C D E F G ...
1
2
3 Col1 Col2
4 15 20
5 16 21
6 ... ...
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?
I read somewhere that we can use DATAROW
in Proc Import
when DBMS=EXCEL
like below:
proc import datafile = "!datafile" out=Table1 DBMS = EXCEL REPLACE;
SHEET = "Sheet1"; GETNAMES=YES; MIXED=YES; USEDATE=YES; SCANTIME=YES; NAMEROW=3; DATAROW=4;
run;
However, SAS cannot recognize the DATAROW
option, giving the error:
ERROR 180-322: Statement is not valid or it is used out of proper order.
There is another way of importing table from Excel like:
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;
Does anyone know how to export a table with an unknown number of rows from .XLSM to SAS?