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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.