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;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 420 views
  • 0 likes
  • 3 in conversation