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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.