BookmarkSubscribeRSS Feed
ramuking003
Calcite | Level 5

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.

3 REPLIES 3
XavierBizoux
SAS Super FREQ

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!

Xavier BIZOUX
Advisory Technical Architect ● Global Enablement and Learning
Technology Transfer and Governance, R&D
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ksharp
Super User
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;


sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1149 views
  • 1 like
  • 4 in conversation