Hi,
I have an Excel file with several sheet.
I need to import to a table the sheet BKH..."
Sometimes the sheet can be named "BKH_0210", sometimes "BKH546", or whatever else beginning by "BKH", I am sure it's the only sheet name containing and beginning by BKH
So I tried:
proc import datafile = "&inputdir./&input_file." DBMS = xlsx OUT = &output_table.; getnames=no; sheet LIKE "BKH%"; run;
But it's not working...I just tried but I already had the feeling it wouldn't work.
Do you have an idea on how I can do it?
@FP12 wrote:
Hi,
I have an Excel file with several sheet.
I need to import to a table the sheet BKH..."
Sometimes the sheet can be named "BKH_0210", sometimes "BKH546", or whatever else beginning by "BKH", I am sure it's the only sheet name containing and beginning by BKH
So I tried:
proc import datafile = "&inputdir./&input_file." DBMS = xlsx OUT = &output_table.; getnames=no; sheet LIKE "BKH%"; run;But it's not working...I just tried but I already had the feeling it wouldn't work.
Do you have an idea on how I can do it?
The LIKE syntax will not work in PROC IMPORT. It only works in PROC SQL.
You can use the EXCEL engine in a Libname statement to determine the names of all the sheets in your Excel file. Then you can find the one that begins with BKH, and then use that name found in your PROC IMPORT.
That could look like:
libname myFile XLSX 'path to my excel file.xlsx';
data want;
set myFile.BKH: ;
run;
Thanks Reeza,
It works perfectly... when there are not spaces character.
What if it's "BK H" instead of "BKH"? I tried and it is not working. Do you know a solution for this?
I have another problem with this solution...
The columns names are extracted from the first row and I don't want.
I want something like:
getnames = no
@FP12 unfortunately I don't think that's possible using the libname method.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.