I have like 30 libraries ( created by another macro as an initial setup). I am checking if my interested dataset exists in the library. How can I do this? The purpose of this code is, if this dataset exists then I want to run another macro/data step. I created the sample. Thank you for your suggestions, and sorry if any mistakes in my sample; I will correct them as I get suggestions.
** Just created the libraries, for example;
libname s1 'D:\New folder';
libname s2 'D:\New folder 1';
data s1.chk;
x='y';
run;
** if dataset 'chk' in 's1' or 's2' library then the
the following code has to run; otherwise need a note
'No dataset exists';
*&lib is the library where the dataset existed;
data chk_&lib;
set &lib.chk;
flag ='Y';
run;
%if %sysfunc(exist(&lib..chk)) %then %do;
/* conditional code */
%end;
Thank you @Kurt_Bremser . This code works. However, I have an extension question. I have 30 libraries. Is there anyway &lib' created automatically by using like dictionary. tables or vcolumn ? otherwise, I have to run a macro for each library.
What should happen if the dataset exists in both libraries?
if data set is present in both libraries, then it should execute the following code and create the chk_s1, chk_s2 datasets.
data chk_&lib;
set &lib.chk;
flag ='Y';
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.