BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

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;

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 5218 views
  • 8 likes
  • 3 in conversation