Problem:
I have 1000s of xlsx sheets that I'm importing. However, they are poorly structured but contain a table that all start with a date-column with either 'date' or 'testdate' as column header (then the column contains dates). This keyword/header can be in various positions in excel (eg row 3 and column 4 or row 5 and column 3).
Solution:
Import xlsx file
create a variable with row-nr (_N_)
Identify row position of keyword ('date' or 'testdate')
import xlsx file at rownum = position given above to capture headers.
My problem lies in identifying the first occurrence of date or testdate searching all columns with unknown column names.
It would help if you could post an example of a sheet you are trying to import. Dummy data is fine if the original data is confidential.
I'd suggest using the XLSX engine in a SAS LIBNAME statement pointing at one of the Excel workbooks, then reading the required worksheet in using a SAS Data Step.
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.