BookmarkSubscribeRSS Feed
jdsdog10
Calcite | Level 5

I have my variable names in line 8, and my data starts at line 14. I'm not able to figure out how to import the data while skipping those other lines. Currently I am importing line 8 exclusively, using getnames, creating an empty table with variable names (over 120). Then importing all the data to a temporary table. Then adding the data from the temporary table to the empty table that has the variable names. It seems like there should be a way to designate the header row and designate a different starting row.

 

*Update: the variable names are important. I have about 20 different excel files, all with the same format, and each file has different variable names (all 120+) that are important for the task at hand. Editing the file isn't an option at the moment.

6 REPLIES 6
Tom
Super User Tom
Super User

What kind of file are you reading?

Tom
Super User Tom
Super User

How is it you are reading only the name row?

Any way here is way that involves reading the file twice. Once starting with the name row and one starting with the data row. Then using PROC DATASETS to rename the variables in the second one with the first row from the first one.

So let's assume you have the name of the XLSX file in the macro variable FNAME.

And also that you are reading from a sheet named TEST.

So this code will create a dataset named VALUES with the data from row 14 using the names from row 8.

 

proc import datafile="&fname" dbms=xlsx out=names replace ;
   getnames=no;
   range="test$A8:";
run;
proc import datafile="&fname" dbms=xlsx out=values replace ;
   getnames=no;
   range="test$A14:";
run;

proc transpose data=names(obs=1) out=name_list;
  var _all_;
run;
proc sql noprint;
  select catx('=',_name_,nliteral(col1))
    into :renames separated by ' '
    from name_list
    where upcase(_name_) ne upcase(col1)
  ;
quit;

proc datasets nolist lib=work;
  modify values ;
    rename &renames;
  run;
quit;
ballardw
Super User

Either edit the file so that the variable names are on row 1 and data starts on row 2

OR

Write a data step to read data. The Infile statement will allow you to tell which row the data starts on by using the Firstobs= option and you pick/set your variable names with Input/informat/attribute statements.

 

Proc Import is designed for reading simple data designed for interchange. Multiple row headings and blank rows are not what it is designed to read.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1244 views
  • 1 like
  • 4 in conversation