I am importing an Excel file into 9.4 using the wizard but need the data to start at line 3 (total 377 lines) and to keep variables in line 1. I cannot seem to get it to do no matter what. Help?
well how do you drop row 2 because nothing I have done works.
Are you saying that your Excel file looks like:
Name1 Name2 junk row val1 val2 val3 val4 val5 val6
To drop that extra row just add a data step.
data want ;
set have (firstobs=2);
run;
Of course the extra row of junk might mess up the SAS's ability to properly define the variable types.
1. Import file wiht proc import
2. remove first two records. _n_ is a pseudorecord number.
proc import..blah;
data want;
set imported;
if _n_< 3 then delete;
run;
What version of SAS are you using. What type of Excel file do you have? Is it XLSX or some older format?
How is you Excel sheet actually arranged? Here is a normal sheet.
Name1 | Name2 |
1 | 2 |
3 | 4 |
Here is one with extra row in the table.
Name1 | Name2 |
1 | 2 |
3 | 4 |
Here is one with extra row before the table.
Name1 | Name2 |
1 | 2 |
3 | 4 |
I made an XLSX file with those three sheets and copied the data to work.
libname in xlsx 'c:\downloads\test3.xlsx';
proc copy inlib=in outlib=work;
run;
Here is what they look like.
Does your file look like any of these? If not what does it look like?
If the names are not in the first row then you need to import without names and add the names back later.
If the names are in the first row then the only option you need is the datarow option.
proc import datafile='c:\downloads\test3.xlsx' out=values replace dbms=xlsx ;
sheet='Sheet4';
datarow=3;
run;
What XLSX sheet looks like
Name1 | Name2 |
Junk | Junk |
1 | 2 |
3 | 4 |
What SAS dataset looks like
NOTE: works the same using XLS file instead of XLSX file.
Show your log use the {i} in editor menu bar to open pop-up window to paste the log contents.
Also exactly what version of SAS are you using?
Are there other issues with the XLS file that might cause trouble for SAS? Merged cells for example?
And if you can pare down the problem XLS file to a small example that still exhibits the issue then post that as an attachment. Although most user of forum would be reluctant to download an XLS file from web.
FWIW I routinely save any Excel file to CSV and work with that as there are more options in Proc Import, such as GUESSINGROWS and data rows. And even then usually modify the data step code generated to read the CSV to be "nicer" in providing useable variable names, consistent lengths if I expect to deal with multiple files in a similar layout, adding variable labels and even data checking code.
Relying on proc import to deal with multiple files often leads to headaches if the data has to be combined later.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.