BookmarkSubscribeRSS Feed
chandu1
Calcite | Level 5

Hi All ,

I would like to delete more than 30 days older log files in DFS path like  "\\data\output\listings\" . The log files has an extension .log2 

Please provide sample program for the above requirement and also if any one can provide code for to run at command prompt for this requirement. I have researched for this requirement ,Below is the sample command using forfiles. Can anyone confirm, can I use forfies for this requirement. Can you modify below command using below example sample log files.

C:\> forfiles /m testfile.txt /c "cmd /c Del testfile.txt " /d -30

For example below are samples log files exist in the dfs path "\\data\output\listings\" .

TEST_X_900_20220616_ 20831.log2

TEST_Y_800_20220310_ 20831.log2

TEST_Z_700_20220205_ 20831.log2

 

I am using below sample code for this requirement but it is not executing . Please help me on this case.

 


%macro mr_clean(dirpath=,dayskeep=30,ext=.log);
data _null_;
length memname $256;
deldate = today() - &dayskeep;
rc = filename('indir',"&dirpath");
did = dopen('indir');
if did then
do i=1 to dnum(did);
memname = dread(did,i);
if reverse(trim(memname)) ^=: reverse("&ext") then continue;
rc = filename('inmem',"&dirpath/"!!memname);
fid = fopen('inmem');
if fid then
do;
moddate = input(finfo(fid,'Last Modified'),date9.); /* see WARNING below */
rc = fclose(fid);
if . < moddate <= deldate then rc = fdelete('inmem');
end;
end;
rc = dclose(did);
rc = filename('inmem');
rc = filename('indir');
run;
%mend mr_clean;

 

%mr_clean(dirpath=\\quintiles.net\enterprise\Apps\GDM_SAS_EDC\DEV\BLIND\BASILEA\RZA01124\DATA\OUTPUT\LISTINGS,dayskeep=30,ext=.log2)

 

Please check the above code and can provide working code for this requirement.

 

 

Thank you .

Regards,

Chandu

 

 

 

 

 

 

 

 

 

 

 

5 REPLIES 5
Kurt_Bremser
Super User

"not executing" tells us next to nothing. Please be more specific.

In particular, always post the log of code that does not work as expected.

If there are no ERRORs or WARNINGs, describe in detail what did not work as expected.

chandu1
Calcite | Level 5

Hi Kurt Bremser,

Thanks for your reply.

Have a look into below code and log. Seems to be the code is not completely executing in SAS EG . Please suggest on this  or you can provide new sas code for to delete more than 30 days log files in DFS shared path.

 

Code:


options symbolgen mprint mlogic;
%macro mr_clean(dirpath=,dayskeep=30,ext=.log);
data _null_;
length memname $256;
deldate = today() - &dayskeep;
rc = filename('indir',"&dirpath");
did = dopen('indir');
if did then
do i=1 to dnum(did);
memname = dread(did,i);
if reverse(trim(memname)) ^=: reverse("&ext") then continue;
rc = filename('inmem',"&dirpath/"!!memname);
fid = fopen('inmem');
if fid then
do;
moddate = input(finfo(fid,'Last Modified'),date9.); /* see WARNING below */
rc = fclose(fid);
if . < moddate <= deldate then rc = fdelete('inmem');
end;
end;
rc = dclose(did);
rc = filename('inmem');
rc = filename('indir');
run;
%mend mr_clean;

%mr_clean(dirpath=\\auintiles.net\enterprise\Apps\GDM_SAS_EDC\DEV\BLIND\VASILEA\RZA01124\DATA\OUTPUT\LISTINGS,dayskeep=30,ext=.log2)

 

Log :

 

1 The SAS System 07:23 Friday, June 24, 2022

1 %_eg_hidenotesandsource;
2 ;*';*";*/;quit;run;
3 OPTIONS PAGENO=MIN;
4 %_eg_restorenotesandsource;
5 %_eg_hidenotesandsource;
6
7 %LET _CLIENTTASKLABEL='Dellog1.sas';
8 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
9 %LET _CLIENTPROJECTPATH='';
10 %LET _CLIENTPROJECTPATHHOST='';
11 %LET _CLIENTPROJECTNAME='';
12 %LET _SASPROGRAMFILE='\\auintiles.net\enterprise\Apps\sasdata\StatOpB\TestingProcHadoop\Purna\Dellog1.sas';
13 %LET _SASPROGRAMFILEHOST='CA2XAPPSAS01D';
14
15 ODS _ALL_ CLOSE;
16 OPTIONS DEV=SVG;
NOTE: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation
marks.
17 GOPTIONS XPIXELS=0 YPIXELS=0;
18 %macro HTML5AccessibleGraphSupported;
19 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) >= 0 %then ACCESSIBLE_GRAPH;
20 %mend;
21 FILENAME EGHTML TEMP;
22 ODS HTML5(ID=EGHTML) FILE=EGHTML
23 OPTIONS(BITMAP_MODE='INLINE')
24 %HTML5AccessibleGraphSupported
25 ENCODING='utf-8'
26 STYLE=HTMLBlue
27 NOGTITLE
28 NOGFOOTNOTE
29 GPATH=&sasworklocation
30 ;
31
32 %_eg_restorenotesandsource;
33
34 %mr_clean(dirpath=\\auintiles.net\enterprise\Apps\GDM_SAS_EDC\DEV\BLIND\VASILEA\RZA01124\DATA\OUTPUT\LISTINGS,dayskeep=30
34 ! ,ext=.log2)
35
36 %_eg_hidenotesandsource;
37
38 %LET _CLIENTTASKLABEL=;
39 %LET _CLIENTPROCESSFLOWNAME=;
40 %LET _CLIENTPROJECTPATH=;
41 %LET _CLIENTPROJECTPATHHOST=;
42 %LET _CLIENTPROJECTNAME=;
43 %LET _SASPROGRAMFILE=;
44 %LET _SASPROGRAMFILEHOST=;
45
46 ;*';*";*/;quit;run;
47 ODS _ALL_ CLOSE;
48
49 %_eg_restorenotesandsource;
50
51
52 %_eg_hidenotesandsource;
53 QUIT; RUN;
54 %_eg_restorenotesandsource;
55

 

 

 

Kurt_Bremser
Super User

This is key:

NOTE: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation
marks.

Something (unbalanced quotes, incomplete macro definition, ...) corrupted your SAS session. Start a fresh session and redo your test; start by running the data _null_ without the macro definition (set the macro variables with %LET).

chandu1
Calcite | Level 5

Hi Kurt Bremser,

 

I have run the code as you suggested but the code was seems to be continuously executing .I was waited more than 10 min and canceled the job. Below is the log. is there any issues in the code ? Please suggest on this.

 

Log :

 

1 The SAS System 13:18 Friday, June 24, 2022

1 %_eg_hidenotesandsource;
5 %_eg_hidenotesandsource;
33
34 %let dirpath=\\auintiles.net\enterprise\Apps\GDM_SAS_EDC\DEV\BLIND\VASILEA\RZA01124\DATA\OUTPUT\LISTINGS;
35 %let dayskeep=30;
36 %let ext=.log2;
37 data _null_;
38 length memname $256;
39 deldate = today() - &dayskeep;
40 rc = filename('indir',"&dirpath");
41 did = dopen('indir');
42 if did then
43 do i=1 to dnum(did);
44 memname = dread(did,i);
45 if reverse(trim(memname)) ^=: reverse("&ext") then continue;
46 rc = filename('inmem',"&dirpath/"!!memname);
47 fid = fopen('inmem');
48 if fid then
49 do;
50 moddate = input(finfo(fid,'Last Modified'),date9.); /* see WARNING below */
51 rc = fclose(fid);
52 if . < moddate <= deldate then rc = fdelete('inmem');
53 end;
54 end;
55 rc = dclose(did);
56 rc = filename('inmem');
57 rc = filename('indir');
58 run;

NOTE: The DATA step has been abnormally terminated.
NOTE: DATA statement used (Total process time):
real time 12:11.62
cpu time 1.18 seconds

59
60 %_eg_hidenotesandsource;

Kurt_Bremser
Super User

Add some diagnostic messages to your code so you can see its progress in the log.

A real time of 12 minutes while only 1 CPU second is used points to very long wait times for the "disk" operation(s) occurring over a network mount.

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
  • 5 replies
  • 350 views
  • 0 likes
  • 2 in conversation