BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fredbell
Fluorite | Level 6

Hi

How would i go about selecting row 3 as the variable names and then say
row 4 to 11?


PROC IMPORT DATAFILE= "c:\Assurance\Scorecard.xls" DBMS=EXCEL out = TotalSubscribers
replace;
SHEET="'Fobe'";
RANGE='a4:ax11';
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;

RUN;




Fred Message was edited by: fredbell

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Editor's note: this is a popular topic.  We've consolidated the best responses in this one Accepted Solution.

 

From @ArtC, answering for the case where the field names are contiguous with the data range.

You are very close. Change your range to include the row with the variable names.

 

From @rsva, using the legacy DBMS=XLS method, which supports NAMEROW=:

 



Proc import datafile="xx.xls"
          dbms=xls replace out=newdata;
         getnames=yes;
         namerow=3;
         datarow=4;
Run;

And from @art297:

 

Fred,

 

If the column names are in a completely different (non-contiguous) part of the sheet, then perhaps you need a two-pass approach.  One way might be to import the variable names and the data separately. E.g.:

PROC IMPORT OUT= WORK.TEST1
DATAFILE= "c:\xltest.xls"
DBMS=EXCEL2000 REPLACE;
RANGE="A2:C2";
GETNAMES=YES;
RUN;

proc sql noprint;
select catt('F',varnum,'=',name)
into :recodes
separated by ' '
from sashelp.vcolumn
where libname="WORK"
and memname="TEST1"
;
quit;

PROC IMPORT OUT= WORK.TEST2
DATAFILE= "c:\xltest.xls"
DBMS=EXCEL REPLACE;
RANGE="A15:C17";
GETNAMES=NO;
RUN;

data want;
set test2 (rename=(&recodes.));
run;

HTH,
Art

View solution in original post

8 REPLIES 8
ArtC
Rhodochrosite | Level 12
You are very close. Change your range to include the row with the variable names.
fredbell
Fluorite | Level 6
Thanks but what if i also need to RANGE='a40:ax60';

How do i get Variable names and then define the range?

Fred
ArtC
Rhodochrosite | Level 12
Do you mean that the variable names are in one range say row three (say a3:aw3), while the data is in another location on the sheet say b40:ax90?
fredbell
Fluorite | Level 6
Yes that is what i mean, thanks.

Fred
art297
Opal | Level 21

Editor's note: this is a popular topic.  We've consolidated the best responses in this one Accepted Solution.

 

From @ArtC, answering for the case where the field names are contiguous with the data range.

You are very close. Change your range to include the row with the variable names.

 

From @rsva, using the legacy DBMS=XLS method, which supports NAMEROW=:

 



Proc import datafile="xx.xls"
          dbms=xls replace out=newdata;
         getnames=yes;
         namerow=3;
         datarow=4;
Run;

And from @art297:

 

Fred,

 

If the column names are in a completely different (non-contiguous) part of the sheet, then perhaps you need a two-pass approach.  One way might be to import the variable names and the data separately. E.g.:

PROC IMPORT OUT= WORK.TEST1
DATAFILE= "c:\xltest.xls"
DBMS=EXCEL2000 REPLACE;
RANGE="A2:C2";
GETNAMES=YES;
RUN;

proc sql noprint;
select catt('F',varnum,'=',name)
into :recodes
separated by ' '
from sashelp.vcolumn
where libname="WORK"
and memname="TEST1"
;
quit;

PROC IMPORT OUT= WORK.TEST2
DATAFILE= "c:\xltest.xls"
DBMS=EXCEL REPLACE;
RANGE="A15:C17";
GETNAMES=NO;
RUN;

data want;
set test2 (rename=(&recodes.));
run;

HTH,
Art

soumoboxi
Calcite | Level 5

Hi, I am using SAS9.3. The above code is importing a maximum of 142 columns. Please help. - Thanks in advance.

ChrisHemedinger
Community Manager

I think you'll need to provide more details about your Excel file and your code/log...or alternatively, work with SAS Tech Support on your specific case.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
rsva
Fluorite | Level 6

Try this

Proc import datafile="xx.xls"

          dbms=xls replace out=newdata;

         getnames=yes;

         namerow=3;

         datarow=4;

Run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 49286 views
  • 1 like
  • 6 in conversation