This is my program. You will see in the end that files are not deleted.
322 /*bestand niet doorsturen als er een fout is */
323 %macro maj ;
324 %let dsid = %sysfunc( open( work.ODU_DASHBOARD_MANUAL_USER , i ) ) ;
325 %let dsid1 = %sysfunc( open( work.ODU_DASHBOARD_MANUAL_USER1 , i ) ) ;
326 %let dsid2 = %sysfunc( open( work.ODU_DASHBOARD_MANUAL_USER2 , i ) ) ;
327 %let dsid3 = %sysfunc( open( work.ODU_DASHBOARD_MANUAL_USER3 , i ) ) ;
328 %let aantobs = %sysfunc( attrn( &dsid , any ) ) ;
329 %let aantobs1 = %sysfunc( attrn( &dsid1 , any ) ) ;
330 %let aantobs2 = %sysfunc( attrn( &dsid2 , any ) ) ;
331 %let aantobs3 = %sysfunc( attrn( &dsid3 , any ) ) ;
332 %let rc = %sysfunc( close( &dsid ) ) ;
333
334 %if &dsid = 0
335 or &dsid1 = 0
336 or &dsid2 = 0
337 or &dsid3 = 0
338 or &aantobs ne 1
339 or &aantobs1 ne 1
12 The SAS System 14:56 Tuesday, October 20, 2020
340 or &aantobs2 ne 1
341 or &aantobs3 ne 1
342 %then %do ;
343 %end ;
344 %else %do ;
345 proc datasets lib = &surrep nolist ;
346 delete ODU_DASHBOARD_MANUAL_USER ODU_DASHBOARD_MANUAL_USER1 ODU_DASHBOARD_MANUAL_USER2
346 ! ODU_DASHBOARD_MANUAL_USER3 ;
347 quit ;
348 data &surrep..ODU_DASHBOARD_MANUAL_USER ( bulkload = yes ) ;
349 set work.ODU_DASHBOARD_MANUAL_USER ;
350 run ;
351 data &surrep..ODU_DASHBOARD_MANUAL_USER1 ( bulkload = yes ) ;
352 set work.ODU_DASHBOARD_MANUAL_USER1 ;
353 run ;
354 data &surrep..ODU_DASHBOARD_MANUAL_USER2 ( bulkload = yes ) ;
355 set work.ODU_DASHBOARD_MANUAL_USER2 ;
356 run ;
357 data &surrep..ODU_DASHBOARD_MANUAL_USER3 ( bulkload = yes ) ;
358 set work.ODU_DASHBOARD_MANUAL_USER3 ;
359 run ;
360 %end ;
361 %mend maj ;
362 %maj ;
NOTE: Deleting SURREP.ODU_DASHBOARD_MANUAL_USER (memtype=DATA).
NOTE: Deleting SURREP.ODU_DASHBOARD_MANUAL_USER1 (memtype=DATA).
NOTE: Deleting SURREP.ODU_DASHBOARD_MANUAL_USER2 (memtype=DATA).
NOTE: Deleting SURREP.ODU_DASHBOARD_MANUAL_USER3 (memtype=DATA).
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.50 seconds
cpu time 0.00 seconds
NOTE: There were 117736 observations read from the data set WORK.ODU_DASHBOARD_MANUAL_USER.
NOTE: The data set SURREP.ODU_DASHBOARD_MANUAL_USER has 117736 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 2.00 seconds
cpu time 0.40 seconds
NOTE: There were 4460 observations read from the data set WORK.ODU_DASHBOARD_MANUAL_USER1.
NOTE: The data set SURREP.ODU_DASHBOARD_MANUAL_USER1 has 4460 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.72 seconds
cpu time 0.01 seconds
NOTE: There were 30562 observations read from the data set WORK.ODU_DASHBOARD_MANUAL_USER2.
NOTE: The data set SURREP.ODU_DASHBOARD_MANUAL_USER2 has 30562 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 1.00 seconds
cpu time 0.12 seconds
NOTE: There were 6656 observations read from the data set WORK.ODU_DASHBOARD_MANUAL_USER3.
NOTE: The data set SURREP.ODU_DASHBOARD_MANUAL_USER3 has 6656 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.49 seconds
cpu time 0.01 seconds
363 proc datasets lib = work nolist ;
364 delete ODU_DASHBOARD_MANUAL_USER: ;
365 quit ;
NOTE: Deleting WORK.ODU_DASHBOARD_MANUAL_USER (memtype=DATA).
NOTE: Deleting WORK.ODU_DASHBOARD_MANUAL_USER1 (memtype=DATA).
NOTE: File WORK.ODU_DASHBOARD_MANUAL_USER1 (memtype=DATA) cannot be deleted because it is in use.
NOTE: Deleting WORK.ODU_DASHBOARD_MANUAL_USER2 (memtype=DATA).
NOTE: File WORK.ODU_DASHBOARD_MANUAL_USER2 (memtype=DATA) cannot be deleted because it is in use.
NOTE: Deleting WORK.ODU_DASHBOARD_MANUAL_USER3 (memtype=DATA).
NOTE: File WORK.ODU_DASHBOARD_MANUAL_USER3 (memtype=DATA) cannot be deleted because it is in use.
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
@krisdesopper wrote:
No. The files are not open or used. As you can see the first file was deleted. The next not.
One suspects that since you used OPEN function without CLOSE before the Proc Datasets that the data set is "in use".
On which operating system is your SAS running?
Completely missed what was hidden in that %SYSFUNC avalanche. To check if datasets exist, do a SELECT in SQL from DICTIONARY.TABLES; or (even better) use SASHELP.VTABLE in a DATA _NULL_ step where you decide for which you create the copy code, either with CALL EXECUTE or by writing to a temporary include file.
Using functions like FILENAME or OPEN in macro code can be tricky, as you MUST take care to close every handle and deassign every fileref; otherwise they accumulate and get in your way.
@krisdesopper wrote:
No. The files are not open or used. As you can see the first file was deleted. The next not.
One suspects that since you used OPEN function without CLOSE before the Proc Datasets that the data set is "in use".
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.