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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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