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.
Hi,
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;
select memname
into :fromXLS separated by '","'
from sashelp.vstable
where libname = "MYXLSX";
quit;
proc sql;
select libname, memname
from sashelp.vstable
where libname = "MYLIB" and memname in ("&fromXLS");
quit;
I had no time to validate that code but it should do the trick.
Have a good day!
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.
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.