BookmarkSubscribeRSS Feed
SASuserlot
Barite | Level 11

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;
4 REPLIES 4
SASuserlot
Barite | Level 11

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.

andreas_lds
Jade | Level 19

What should happen if the dataset exists in both libraries?

SASuserlot
Barite | Level 11

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;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2083 views
  • 0 likes
  • 3 in conversation