LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2003, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 28 Aug 2003 10:56:53 -0400
Reply-To:   "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Fehd, Ronald J. (PHPPO)" <rjf2@CDC.GOV>
Subject:   Re: Macro to delete previous datasets automatically
Comments:   cc: William <tien.w@MELLON.COM>
Content-Type:   text/plain

> From: William [mailto:tien.w@MELLON.COM] > I run a job bi-weekly and save a sas permanent dataset to > sas library. I need to erase datasets of previous month so > that current month datasets have enough space to store. > > Here is the macro: > %MACRO DELLAST(INDATE) ; > DATA _NULL_; > D28AGO = &INDATE - 28; > MMDD = SUBSTR(PUT(D28AGO,YYMMDD6.),3,4); > CALL SYMPUT('MMDD',MMDD); > RUN; > PROC DATASETS LIB = SASLIB; * SASLIB is DDname called from JCL *; > DELETE D&MMDD; > %MEND ; > %DELLAST('28AUG2003'D) > > Since the indate is user run date, there is no guarantee that > dataset of (indate - 28) exist. Furthermore, I want to > implement this macro to all programs with different rundates.

you are passing a parameter MMDD -- which is a suffix of a data set name -- to your delete statement in proc DataSets.

in the worst case this results in generating a delete statement that has invalid data set name.

I suggest you pass the complete delete statement: delete <Data Set Name>; to proc DataSets,

in the worst case there is no delete statement and proc DataSets does nothing, most gracefully, I might add.

set code below .sig which you will note requires no macro only macro variables as parameters

Ron Fehd the SQL into:macroVar maven CDC Atlanta GA USA RJF2@cdc.gov

By using your intelligence you can sometimes make your problems twice as complicated. -- Ashleigh Brilliant

%Let Prefix =

%Let Libref = Work;%*Testing; %Let SQLprint = Print;%*Testing; %*Let SQLprint =noPrint;%*production;

PROC Sql &SQLprint.; select 'delete ' !! MemName !! ';' into :List2Del separated by ' ' from Dictionary.Tables where LibName eq "&Libref." and substr(MemName ,1 ,%length(&Prefix.) ) eq "&Prefix." ;quit;

PROC Datasets library = &Libref. memtype = data nolist nowarn ;*end options; &List2Del. ;quit;

%symdel LibRef List2Del SQLprint Prefix; run;


Back to: Top of message | Previous page | Main SAS-L page