data _null_;
set &table..pgpr_rowcnt end=eof;
where rowcount =0 ;
if _n_=1 then call execute(
"proc datasets library = &table nolist nowarn memtype=(data view); delete ");
call execute(relname);
call execute (" ");
if eof then call execute(";run;quit;");
run;
CALL EXECUTE version (untested)
If the list is longer than can be stored in macro variable then generate code instead of a macro variable.
filename code temp;
data _null_;
set &table..pgpr_rowcnt end=eof;
where rowcount =0 ;
if _n_=1 then put
"proc datasets library = &table nolist nowarn memtype=(data view);"
/ " delete " @
;
put relname @;
if eof then put ';' / 'run;quit;' ;
run;
%include code / source2;
data _null_;
set &table..pgpr_rowcnt end=eof;
where rowcount =0 ;
if _n_=1 then call execute(
"proc datasets library = &table nolist nowarn memtype=(data view); delete ");
call execute(relname);
call execute (" ");
if eof then call execute(";run;quit;");
run;
CALL EXECUTE version (untested)
Or, similar to @Tom 's example but with CALL EXECUTE, there is no limit on how many table names could be listed.
Tables (SAS data sets) from a library or variables from a data set?
Lets see if you can clean up your description to be a bit clearer of what you have and what you want to do.
You say" table pgpr_rowcnt which will store 100000s of coloumns" and then show an example of exactly 2 columns. So how do those 2 columns relate to Pgpr_rowcnt?
Call execute comes to mind, no macro variable involved.
data _null_; set &table..pgpr_rowcnt end=Lastone; if _n_=1 then call execute(" proc datasets library = &table nolist nowarn memtype=(data view);"); if rowcount= 0 then call execute('delete '||relname||';'); if lastone then call execute ('run; quit;'); run;
This in effect stacks the code for proc datasets into the execution queue.
Or use similar syntax to write the text to a program file and use %include to call the created code. This has the advantage of you can review the created code for syntax problems and have a document of what was done to your data and when.
Note: Proc Datasets uses QUIT to end the procedure because it supports run group processing and a single run might be followed by others, especially if used interactively.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.