Hi Everyone,
I need help
can we create a loop for finding external source in a loop .
If source exist --ok
else it has to wait for source 10mins
EXISTS function is returning false can any one help me
see the attachment for log
libname STPSAMP "/pbr/sfw/sas/940/SASFoundation/9.4/samples/inttech";
OPTIONS SYMBOLGEN MPRINT MLOGIC;
PROC SQL;
SELECT memname INTO:TNAME separated by ' '
FROM DICTIONARY.TABLES
WHERE LIBNAME ='STPSAMP';
QUIT;
%PUT &TNAME;
%macro checkds;
%LET one=&TNAME.;
%let cnt=1;
%if %sysfunc(exist(STPSAMP.&one.)) %then %do;
proc print data=sashelp.air;
run;
%end;
%else %do;
data _null_;
file print;
put #3 @10 "Data set &dsn. does not exist";
run;
%end;
%mend checkds;
%checkds;
if you look at the log, you'll see that &tname resolves to ODSSTYLE STPBGT STPEURO STPSALE. There are four datasets in the directory.
You need to separate them out - try %scan(&tname, 1, %str( )) to check the existence of the first one.
On top of what @LaurieF writes: If your real code also just checks the existence of tables based on a query of dictionary.tables then then code is pretty useless as such a query will only return tables that do exist.
How do you want to call the macro? Do you just pass in a single SAS table per call or do you need to pass in a whole list of SAS tables - or are these SAS tables at all or external files like .csv?
How would you create the list of expected tables or files? Could this be something you store in a SAS table to begin with?
Again:
- Are we looking for the existence of SAS tables or the existence of external files?
- How is the information stored what's expected?
- Is that in a table or just in code?
- For how many such tables or files do you have to check?
May be below will point you into the right direction.
%macro checkds(dsn,time_to_check_in_sec=900,check_interval_in_sec=30);
%local startdttm;
%let startdttm=%sysfunc(datetime());
%do %while( %sysfunc(sum(%sysfunc(datetime()),-&startdttm))<&time_to_check_in_sec );
%if %sysfunc(exist(&dsn)) %then
%do;
proc print data = &dsn;
run;
%goto done;
%end;
%put &=startdttm;
data _null_;
call sleep(&check_interval_in_sec,1);
stop;
run;
%end;
data _null_;
file print;
put #3 @10 "Data set &dsn. does not exist";
run;
%done: ;
%mend checkds;
%checkds(sashelp.class);
%checkds(sashelp.class_not_exist);
You could now just call the macro for all the tables you want to check or you can have these tables in a SAS table and then use a data _null_ step with call execute to call the macro once per table in this control table with expected SAS tables.
@SRINIVAS_N wrote:
Intially all the tables are in external
Using libname tables are stored in local location.if dataset are existed no
problem,if dataset are not there then it has search for dataset for 15mins
From where do you know the dataset names you are looking for?
Do you have them in a dataset, or in an external file, or are they fixed and can be hardcoded into the program?
Or do you want to do something with any dataset that exists in the library, regardless of its name?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: