DATA Step, Macro, Functions and more

how to compare the datasets name and the imported excel sheets name

Reply
Occasional Contributor
Posts: 6

how to compare the datasets name and the imported excel sheets name

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.

SAS Employee
Posts: 10

Re: how to compare the datasets name and the imported excel sheets name

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!

Super User
Super User
Posts: 7,401

Re: how to compare the datasets name and the imported excel sheets name

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.

Super User
Posts: 9,681

Re: how to compare the datasets name and the imported excel sheets name

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;


Ask a Question
Discussion stats
  • 3 replies
  • 170 views
  • 1 like
  • 4 in conversation