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
PROC Star

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;

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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