Sure. Since you still haven't described what you have or what you are trying to achieve we can only give examples of patterns that you can try to adopt.
You can write code to a text file and use %INCLUDE to run it. That has the advantage of letting you use the power of the PUT statement and also for you to review the code before running it to debug the code generation logic.
filename code temp;
data _null_;
set have end=eof;
file code ;
if exist(tab) then put
'insert into status_tech (table_name,table_count) '
'select ' tab :$quote. ',count(*) from ' tab ';'
;
run;
proc sql;
%include code ;
quit;
If you want to try to figure out macro code then make a macro that takes as input a list of names. Then call it with the list of tables to count.
%macro counts(tablist);
%local i tab ;
proc sql;
%do i=1 %to %sysfunc(countw(&tablist,%str( )));
%let tab=%scan(&tablist,&i,%str( ));
%if %sysfunc(exist(&tab)) %then %do;
insert into status_tech (table_name,table_count)
select "&tab",count(*) from &tab
;
%end;
%end;
quit;
%mend ;
%counts(fred sam);
If you are talking about checking members in a SAS library then just query to SAS metadata and skip the counting. That is easy if you have the list of names in a macro variable. Preferable already quoted.
%let tablist="fred" "sam";
proc sql;
insert into status_tech (table_name,table_count)
select memname,nobs
from dictionary.tables
where libname='MYLIB'
and memname in %upcase(&tablist)
;
quit;