Help using Base SAS procedures

reading .xls into SAS

Reply
New Contributor
Posts: 3

reading .xls into SAS

Does anyone knows how to read the .XLS file using proc import method when the excel file has two headers and not one.  If the file contain only one header SAS 9.3 is perfectly able to read it, but unfortunately with two

Headers it fails every time. 

example: This works if the excel sheet has only one header,

%macro inp(dat,dsn);

proc import datafile="/project/myfiles/data/&dat"

  out=&dsn

  dbms=xls replace;

  DATAROW=2;

  getnames=yes;

run;

I tried everything(below) that I knew for two headers file,but SAS 9.3 can not read it.

First failedTrial,

%macro inp(dat,dsn);

proc import datafile="/project/myfiles/data/&dat"

  out=&dsn

  dbms=xls replace;

  DATAROW=3;

  getnames=yes;

run;

Second failed Trial,

%macro inp(dat,dsn);

proc import datafile="/project/myfiles/data/&dat"

  out=&dsn

  dbms=xls replace;

  startrow=2;

  DATAROW=3;

  getnames=yes;

run;

Second failed Trial,

%macro inp(dat,dsn);

proc import datafile="/project/myfiles/data/&dat"

  out=&dsn

  dbms=xls replace;

  startrow=2;

  DATAROW=3;

  getnames=NO;

run;

if Anyone can share their experience with this , if had one, it will be definitely appreciated.

Verleger

Super User
Super User
Posts: 6,687

Re: reading .xls into SAS

You should be able to use both rows for names.

SAS/ACCESS(R) 9.2 Interface to PC Files: Reference, Second Edition

proc import datafile="&fname" dbms=xls out=test4 replace;

  startrow=3 ; namerow=1; endnamerow=2;

run;

New Contributor
Posts: 3

Re: reading .xls into SAS

Thanks Tom for your Input. 

But unfortunately those methods do not work with SAS 9.3 version and also I have Office 2010 which I am not sure if it contributes to the failure as being compatible or not.

I believe those method such as namerow or endnamerow will be only useful with earlier version of SAS.

IF there was a way that I could  skip the first row and only read the second row as my column names and third row as start of data , then that will do it also for me. but for now SAS 9.3 refuses

to accept my second row as column names and my data starting at third row.  Just trying to tell SAS that my first row is garbage ! do not read it.

Super User
Super User
Posts: 6,687

Re: reading .xls into SAS

Works fine for me with 9.3 on Unix. 

%let wdir=%sysfunc(pathname(work));

data test ;

  input (x y z) ($) ;

cards;

a b c

1 2 3

;;;;

proc export data=test outfile="&wdir/test.xls"

  dbms=xls replace ;

run;

proc import datafile="&wdir/test.xls" out=test1

  dbms=xls replace ;

run;

proc import datafile="&wdir/test.xls" out=test2

  dbms=xls replace ;

  namerow=2; startrow=3;

run;

data _null_;

set test1 ;

put (_all_) (=);

run;

data _null_;

set test2;

put (_all_) (=);

run;

Super User
Posts: 9,766

Re: reading .xls into SAS

Try RANGE=  option with proc import + excel .

Ask a Question
Discussion stats
  • 4 replies
  • 324 views
  • 0 likes
  • 3 in conversation