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;

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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