DATA Step, Macro, Functions and more

Import Excel file with no-use Text info in the first few rows.

Accepted Solution Solved
Reply
Super Contributor
Posts: 417
Accepted Solution

Import Excel file with no-use Text info in the first few rows.

Hello Everyone,

 

I have to import Excel expenditure form. The first 11 row is non-standard with all company information and I dont need it. So I should start from row 12.

And the last few rows contain requirement which I dont need them either.

I attached sample file here.

 

My approach to it is to import from row 12, and then delete any row after the Total number.

 

I use the following code but can get the import done. 

Can anyone help, please?

 

Thank you so much,

 

HC


data TimeHour ;
infile "C:\Users\Original Files\test.xlsx"
firstobs=12
dlm=','  dsd truncover ;
input Date date9.	Start :$100 End :$100 Hotel :$100 GroundTransit :$100	Airfare	CarRental	Meals	
Phone	Miles	MileageReimbursment	Misc :$100	Description	:$100 CompanyPaid	col1 Total

;run;

 

 


Accepted Solutions
Solution
‎09-12-2017 03:20 PM
Super User
Posts: 19,822

Re: Import Excel file with no-use Text info in the first few rows.

You can't use a data step to read an XLSX file. 

 

If you convert it to CSV or text you can process it as desired.

 

Or you can try the RANGE specification in PROC IMPORT. I'd probably specify the RANGE - you only need to know the start cell - and then post process the data to remove the last lines. If you know the full range that's easier.

View solution in original post


All Replies
Solution
‎09-12-2017 03:20 PM
Super User
Posts: 19,822

Re: Import Excel file with no-use Text info in the first few rows.

You can't use a data step to read an XLSX file. 

 

If you convert it to CSV or text you can process it as desired.

 

Or you can try the RANGE specification in PROC IMPORT. I'd probably specify the RANGE - you only need to know the start cell - and then post process the data to remove the last lines. If you know the full range that's easier.

Super Contributor
Posts: 417

Re: Import Excel file with no-use Text info in the first few rows.

So I save the file as CSV.

But when I run the code, still data not imported properly.

 

Super Contributor
Posts: 417

Re: Import Excel file with no-use Text info in the first few rows.

Sorry, I fix it.

Thank you.

HC

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 123 views
  • 0 likes
  • 2 in conversation