11-08-2016 02:51 AM
I have a library with 5 datasets(for eg: a,b,c,d,e,f) and i have a excel file with 3 sheets (sheet name: a,e,d). i need to do some process only for the matching datasets names in both excel as well as in datasets. the datasets name not matched with excel sheet name should throw an exception like "dataset f is no in excel file". can anyone help me to solve this.
11-08-2016 03:27 AM
You can use the SASHELP.VSTABLE as dataset to find tables that are used in multiple libraries. Here is a simple code that should list all the tables in a library which have the same name as tables (worksheets) from an Excel file.
libname myxlsx XLSX 'c:\demo.xlsx';
libname myLIB 'c:\temp';
proc sql noprint;
into :fromXLS separated by '","'
where libname = "MYXLSX";
select libname, memname
where libname = "MYLIB" and memname in ("&fromXLS");
I had no time to validate that code but it should do the trick.
Have a good day!
11-08-2016 04:45 AM
So, are you sure the datasets Exactly match the Excel file? How have you tested this, how are you accessing the Excel file? If your reading in data then you can simply state:
proc sql; create table DATASETS_IN_BOTH as select MEMNAME from SASHELP.VTABLE where LIBNAME="<excel libname>" and MEMNAME in (select distinct MEMNAME from SASHELP.VTABLE where libname="<dataset libname"); quit;
That will give you a dataset with all the matching dataset names - you could also just merge the two. However it is likely that if your dealing with Excel data, then you may have naming issues and plenty of other problems.
11-09-2016 02:35 AM
CODE NOT TESTED. libname xx xlsx 'c:\temp\x.xlsx'; proc sql; select upcase(memname) from dictionary.members where libname='XX' except select upcase(memname) from dictionary.members where libname='MYLIB' ; quit;