Sample 51896: SAS® Drug Development 3.5 Remote API Build 60 Macros - Inventory containers and objects in a Trash Can and delete them base on date or other criteria
The code in the Full Code tab above illustrates how to inventory containers and objects in a Trash Can and delete them base on date or some other criteria.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Enter path of the trash can*/
%let davpath=%str(< Instance UNIX path with Trashcan >);
/* Enter URL*/
%sasdrugdev_login(url=%str(< Instance HTTPS path >),sdduserid=&_SDDUSR_,sddpassword=&_SDDPW_);
/* List the contents of the trash can folder*/
%sasdrugdev_getobjects(sddpath=&davpath, dsname=work._getobjects_,recursivelevel=1);
%global delname _swdPropValue_ loop loop2;
data objs cont;
set work._getobjects_;
if name="trash" then delete; /* Make trash a macro variable based on name of container in davpath */
if iscontainer = 1 then output cont;
else output objs;
run;
data work.update;
set objs nobs=num_obs;
retain count 0;
count = count +1;
delname2 = "&davpath" || '/' || name;
call symput('udate'||left(count), strip(delname2));
call symput('loop1',count);
call symput ('now', 'date_deleted:' || "&sysdate");
run;
data work.update2;
set cont nobs=num_obs;
retain count 0;
count = count +1;
delname2 = "&davpath" || '/' || name;
call symput('udate2'||left(count), strip(delname2));
if num_obs=. then do;
call symput('loop2',"0");
end;
else do;
call symput('loop2',num_obs);
end;
run;
%macro getprop;
data _null_;
set work._fileprops_;
if name = 'keywords' then call symput('_swdPropValue_', value);
run;
%mend;
%macro mod_date;
data _null_;
set update;
%if &loop1 = %str() %then %do;
%put 'NOTE: There is nothing to delete.';
%end;
%else %do;
%do i = 1 %to &loop1;
%sasdrugdev_getfileprops(sddpath=%str(&&udate&i), dsname=work._fileprops_);
%getprop;
%if %length(&_swdPropValue_) < 3 %then %do;
%sasdrugdev_setfileproperty(sddpath=%str(&&udate&i), propname=%str(keywords), propvalue=&now);
%end;
%else %if %substr(&_swdPropValue_ ,1 ,13) = %str(date_deleted:) %then ;
%else %do;
%sasdrugdev_setfileproperty(sddpath=%str(&&udate&i), propname=%str(keywords), propvalue=&now);
%end;
%end;
%end;
run;
%mend mod_date;
%mod_date;
%macro mod_date2;
data _null_;
set update2;
%if &loop2 = %str() %then %do;
%put 'NOTE: There is nothing to delete';
%end;
%else %do;
%do i = 1 %to &loop2;
%let newname = %str(&&udate2&i);
%sasdrugdev_getcontainerprops(sddpath=%str(&newname), dsname=work._containerprops_);
%getprop;
%if %length(&_swdPropValue_) < 3 %then %do;
%sasdrugdev_setcontainerproperty(sddpath=%str(&&udate2&i), propname=%str(keywords), propvalue=&now);
%end;
%else %if %substr(&_swdPropValue_ ,1 ,13) = %str(date_deleted:) %then ;
%else %do;
%sasdrugdev_setcontainerproperty(sddpath=%str(&&udate2&i), propname=%str(keywords), propvalue=&now);
%end;
%end;
%end;
run;
%mend mod_date2;
%mod_date2;
%sasdrugdev_getobjects(sddpath=&davpath, dsname=work.objects, recursivelevel=1);
data objects2 containers;
set work.objects;
if name="trash" then delete; /*make trash a macro variable based on name of container in davpath*/
if iscontainer = 1 then output containers;
else output objects2;
run;
data work.delete(drop=dot_pos);
set work.objects2;
length delname $ 200;
delname= "&davpath" || "/" || left(trim(name));
dot_pos = index(name, '.');
extend = substr(name,dot_pos+1);
file_date=datepart(input(dateTimeString,anydtdtm21.));
now = today();
diff = now - file_date;
/* Enter criteria for deletion of objects*/
run;
proc print data=work.objects2;
title 'Printout of objects in Trashcan';
run;
data work.delete2(drop=dot_pos file_date);
set work.containers;
length delname $ 200;
delname= "&davpath" || "/" || left(trim(name));
dot_pos = index(name, '.');
extend = substr(name,dot_pos+1);
file_date=datepart(input(dateTimeString,anydtdtm21.));
now = today();
diff = now - file_date;
/* Enter criteria for deletion of containers */
/* like - if diff ge 4 */
run;
proc print data=work.containers;
title 'Printout of containers in Trashcan';
run;
%let loop =0;
data objects;
set delete nobs=nobs;
retain count 0;
count = count +1;
call symput('woof'||left(count), strip(delname));
call symput('loop',count);
run;
%put 'NOTE: This is the value of the macro variable loop &loop.;
proc print data = delete;
title 'Printout of objects to delete from Trashcan';
run;
%let loopc =0;
data containers;
set delete2 nobs=nobs;
retain count 0;
count = count +1;
call symput('woof2'||left(count), strip(delname));
call symput('loopc',count);
run;
%put 'NOTE: This is the value of the macro variable loopc &loopc;
proc print data = delete2;
title 'Printout of containers to delete';
run;
%macro delobject;
data _null_;
set objects;
%if &loop = %str() %then %do;
%put 'NOTE: There is nothing to delete';
%end;
%else %do;
%do i = 1 %to &loop;
%sasdrugdev_deletefile(sddpath=&&woof&i);
%end;
%end;
run;
%mend delobject;
%delobject;
%macro delcontainer;
data _null_;
set containers;
%if &loopc = %str() %then %do;
%put 'NOTE: There is nothing to delete.';
%end;
%else %do;
%do i = 1 %to &loopc;
%sasdrugdev_deletecontainer(sddpath=&&woof2&i);
%end;
%end;
run;
%mend delcontainer;
%delcontainer;
%sasdrugdev_getobjects(sddpath=&davpath, dsname=work.after_del);
Title 'print out of the trashcan after the delete has run';
proc print data=work.after_del;
run;
%sasdrugdev_logout;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
SAS® Drug Development 3.5 Remote API Build 60 Macros - Inventory containers and objects in a Trash Can and delete them base on date or other criteria
Date Modified: | 2013-12-20 10:58:54 |
Date Created: | 2013-12-19 19:35:49 |
Operating System and Release Information
SAS System | SAS Drug Development | Microsoft Windows XP 64-bit Edition | | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
Microsoft® Windows® for x64 | | |
Microsoft Windows 8 | | |
Microsoft Windows XP Professional | | |
Windows 7 Enterprise 32 bit | | |
Windows 7 Enterprise x64 | | |
Windows 7 Professional 32 bit | | |
Windows 7 Professional x64 | | |
Windows 7 Ultimate 32 bit | | |
Windows 7 Ultimate x64 | | |
Windows Vista | | |
Windows Vista for x64 | | |