OLDEST_ALLOWED=put(intnx('month',today(),-25),yymmn6.);
Hi Reez,
I tried your code,used libname concat, but it deleted only the first libname, location file, and rest dint get deleted.
libname A '/data/test1/a1/DATASET';
libname B '/data/test2/a2/DATASET';
libname C '/data/test3/a3/DATASET';
libname CONCAT (A B C );
%let table=;
data _null_;
OLDEST_ALLOWED='catt(year(today())-2,"_",month(today())-2)';
do until(symget('table')=' ');
RC=dosubl( 'data _null_;'
||'call symputx("table"," ");'
||'set SASHELP.VSTABLE; '
||'where LIBNAME="CONCAT" and '
||'trim(MEMNAME) like "%20____" and '
||'substr(MEMNAME, length(MEMNAME)-5,6) <' ||quote(OLDEST_ALLOWED)
||';call symputx("table",MEMNAME); stop; run;');
if lengthn(symget('table')) then
CR=dosubl( 'proc delete data=CONCAT.'||symget('table')||';run;');
end;
run;
I did say your oldest_allowed was incorrect. Use Chris' version.
Month returns a value between 1 and 12. If it's January your second term will edd up negative.
This works.
Don't change things around unless you know what you are doing.
2 issues with your code:
1) you added an underscore, so the length of the date suffix is different
2) OLDEST_ALLOWED is badly constructed and fails for single-digit months.
option dlcreatedir source2;
libname A "%sysfunc(pathname(work))\a1";
libname B "%sysfunc(pathname(work))\a2";
libname C "%sysfunc(pathname(work))\a3";
libname CONCAT (A B C );
data A.A201201
B.A201201
C.A201201
C.A201202;
x=1;
run;
%let table=;
data _null_;
OLDEST_ALLOWED=put(intnx('month',today(),-25),yymmn6.);
do until(symget('table')=' ');
RC=dosubl( 'data _null_;'
||'call symputx("table"," ");'
||'set SASHELP.VSTABLE; '
||'where LIBNAME="CONCAT" and '
||'trim(MEMNAME) like "%20____" and '
||'substr(MEMNAME, length(MEMNAME)-5,6) <' ||quote(trim(OLDEST_ALLOWED))
||';call symputx("table",MEMNAME); stop; run;');
if lengthn(symget('table')) then
CR=dosubl( 'proc delete data=CONCAT.'||symget('table')||';run;');
end;
run;
OK. I saw your second version, after
OLDEST_ALLOWED='catt(year(today())-2,"_",month(today())-2)';
Anyway you can run my latest program as is and see that it does what you want.
Modify it to suit your needs.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.