BookmarkSubscribeRSS Feed
laxmanpai
Calcite | Level 5

Hi Team,

 

Could you let me know how to delete the log files from the Logs Folder in SAS which are older than 1 month. 

Currently i am manually deleting the files from this folder.

 

Is there a SAS job which can be written or any script which can be auto triggered ?.

 

Regards

Laxman 

6 REPLIES 6
laxmanpai
Calcite | Level 5

I want this through SAS DI Studio job or any other script which will get auto triggered

andreas_lds
Jade | Level 19

A solution depends on the os of the sas server. On a windows server i would use something like the solution posted on https://stackoverflow.com/questions/17829785/delete-files-older-than-15-days-using-powershell.

 

laxmanpai
Calcite | Level 5

Thank you.

 

Also wanted to know whether it can be done through SAS jobs in DI studio.

Patrick
Opal | Level 21

@laxmanpai wrote:

Thank you.

 

Also wanted to know whether it can be done through SAS jobs in DI studio.


DI Studio is just generating and executing SAS code. 

If XCMD is set you can execute OS level commands via SAS.

Proc Options option=xcmd; run;  will tell you what's set.

 

IF your compute server where SAS executes is Unix/Linux then what you want can be done with a single command (Unix find ) that you then can call out of SAS via Filename pipe or system()/call system();

 

Using DIS just a single node with user written code.

 

laxmanpai
Calcite | Level 5

Thank you

Kurt_Bremser
Super User

See this piece of SAS code which extracts the modification timestamp for files in a directory:

data times;
length dref fref $8 fname $200;
rc = filename(dref,"name of your logs directory");
did = dopen(dref);
if did
then do;
  do i = 1 to dnum(did);
    fname = dread(did,i);
    rc = filename(fref,cats("~/",fname));
    fid = fopen(fref);
    if fid
    then do;
      modified = input(finfo(fid,foptname(fid,5)),nldatm30.);
      rc = fclose(fid);
      output;
    end;
    rc = filename(fref);
  end;
  rc = dclose(did);
end;
rc = filename(dref);
format modified e8601dt19.;
drop dref fref rc did fid i;
run;

From this dataset, you can then run a data step which uses the FDELETE Function  (if you're comfortable with the code once you tested it, you can add the FDELETE immediately before the OUTPUT).

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1340 views
  • 0 likes
  • 4 in conversation