<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dynamically get the dataset name and count of datasets and update the table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640988#M191002</link>
    <description>I would like to correct your understanding.&lt;BR /&gt;&lt;BR /&gt;In your example, fred and sam is a values to the variables 'tab'. Now&lt;BR /&gt;assume fred and sam is some SAS datasets name ,then you have to count the&lt;BR /&gt;observations from  the datasets 'Fred' and 'Sam' and write it to&lt;BR /&gt;test.status_tech.&lt;BR /&gt;&lt;BR /&gt;E.g. test.status_tech should  looks like&lt;BR /&gt;&lt;BR /&gt;Table_name Table_count&lt;BR /&gt;Fred               12&lt;BR /&gt;Sam               44&lt;BR /&gt;</description>
    <pubDate>Sat, 18 Apr 2020 18:24:36 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2020-04-18T18:24:36Z</dc:date>
    <item>
      <title>Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640953#M190988</link>
      <description>&lt;P&gt;I'm trying to dynamically get the table name and table count from macro and want to update it&amp;nbsp;in another table&amp;nbsp;, but I'm unable to get it done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given below the code which I tried. Here 'tab' variable will have the table names and it is dynmaic. It&amp;nbsp;may have&amp;nbsp;one table name upto many but it will not be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume if 'tab' has two table names, then for each table name, I'm trying to execute the macro&lt;/P&gt;
&lt;P&gt;STATUS_TECH_UPDATE to get the table name and table count and update the table test.status_tech&amp;nbsp;&amp;nbsp;but it is not executing as I excepted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In simple terms, if the macro variables has two dataset names, then I need two records in test.status_tech with table names and count of records for each table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume if the 'tab' variable has values&amp;nbsp; 'Account_Balance' and 'Customer' then I want to insert two records into test.status_tech table as follows. 'tab' can hold any number of values and it is dynamic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;test.status_tech:&lt;/U&gt;&lt;/P&gt;
&lt;TABLE width="203"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="125"&gt;table_name&lt;/TD&gt;
&lt;TD width="78"&gt;table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Account_Balance&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Customer&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appericiate if someone of you help me resolve the issue. I'm OK with any other apporach as well.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;options symbolgen mlogic mprint;

/*Get the RUN_ID*/
proc sql;
select "'"||compress(RUN_ID)||"'" into :mac separated by ","
from test.status_tech;
quit;

/*Macro to run for each dataset to get the table_name and table_count */

%MACRO STATUS_TECH_UPDATE(tab);                                                                                                                                       
   %put &amp;amp;tab; 
   %put "inside macro";
     proc sql;
	create table &amp;amp;tab AS
    select count(*) AS COUNT, B.RUN_ID from test.&amp;amp;tab A, STATUS_TECH B
	where A.RUN_ID = B.RUN_ID;
    quit;

    proc sql;
    update test.status_tech(where = (RUN_ID IN (&amp;amp;mac.))) as s_m
	set table_name  =&amp;amp;tab.;
	table_count =(select count from &amp;amp;tab.);
	quit;
     
%MEND;
    
/*pass value to the macro*/
/*tab variable holds the table name*/
data LD_TABLES_1(keep=table);
set FileList_1;
call symput("LD_TABLES",table);
tab=SYMGET('LD_TABLES'); /*LD_TABLES resolves to table names*/
call execute('%STATUS_TECH_UPDATE('||tab||'); ');
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MLOGIC(STATUS_TECH_UPDATE):  Beginning execution.
MLOGIC(STATUS_TECH_UPDATE):  Parameter TAB has value ACCOUNT_BALANCE
MLOGIC(STATUS_TECH_UPDATE):  %PUT &amp;amp;tab
SYMBOLGEN:  Macro variable TAB resolves to ACCOUNT_BALANCE
GL_ACCOUNT_BALANCE_SEGMENT
MLOGIC(STATUS_TECH_UPDATE):  %PUT "inside macro"
"inside macro"
MPRINT(STATUS_TECH_UPDATE):   proc sql;
SYMBOLGEN:  Macro variable TAB resolves to ACCOUNT_BALANCE
MPRINT(STATUS_TECH_UPDATE):   create table ACCOUNT_BALANCE AS select count(*) AS COUNT, B.RUN_ID from 
test.ACCOUNT_BALANCE A, STATUS_TECH B where A.RUN_ID = B.RUN_ID;
MPRINT(STATUS_TECH_UPDATE):   quit;
MPRINT(STATUS_TECH_UPDATE):   proc sql;
SYMBOLGEN:  Macro variable TAB resolves to ACCOUNT_BALANCE
MPRINT(STATUS_TECH_UPDATE):   update test.status_tech set table_name =ACCOUNT_BALANCE;
MPRINT(STATUS_TECH_UPDATE):   table_count =(select count from  &amp;amp;tab.);
MPRINT(STATUS_TECH_UPDATE):   quit;
MLOGIC(STATUS_TECH_UPDATE):  Ending execution.&lt;/PRE&gt;
&lt;PRE style="width: 890px; height: 282px;"&gt;&lt;BR /&gt;1         +
          proc sql;     update test.status_tech  set table_name

2         + =ACCOUNT_BALANCE;
ERROR: The following columns were not found in the contributing tables: ACCOUNT_BALANCE.
ERROR: The following columns were not found in the contributing tables: ACCOUNT_BALANCE
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
2         +                               *table_count =(select count from tab.);  quit;
NOTE: The SAS System stopped processing this step because of errors.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 16:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640953#M190988</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-18T16:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640958#M190989</link>
      <description>&lt;P&gt;Could you share some example data?&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 15:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640958#M190989</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-18T15:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640960#M190990</link>
      <description>&lt;P&gt;Assume if the 'tab' variable resolves to 'Account_Balance' and 'Customer' then I need the output as follows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="203"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="125"&gt;table_name&lt;/TD&gt;
&lt;TD width="78"&gt;table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Account_Balance&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Customer&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sat, 18 Apr 2020 15:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640960#M190990</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-18T15:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640962#M190991</link>
      <description>&lt;P&gt;You want us to help you, but give us example data which aren't data... Don't be lazy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are:&amp;nbsp;status_tech table and run_id variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 15:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640962#M190991</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-18T15:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640965#M190992</link>
      <description>&lt;P&gt;Please explain in detail what you are trying to do, and if possible give the larger context.&lt;/P&gt;
&lt;P&gt;The sense I get from looking at the code is that you want to count the number of observations in some table based on the value of some variable.&amp;nbsp; Isn't that what PROC FREQ is for?&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 15:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640965#M190992</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-18T15:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640966#M190993</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can forget about the run_id variable which I used in my code. I want to insert records into test.status_tech based on the values from the variable 'tab'. If It has one value, then I want to insert one record into&amp;nbsp;test.status_tech table and if it has two values then I need to insert&amp;nbsp; two&amp;nbsp;records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume if the 'tab' variable has values&amp;nbsp; 'Account_Balance' and 'Customer' then I want to insert two records into test.status_tech table as follows. 'tab' can hold any number of values and it is dynamic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;test.status_tech is a empty table and we have to feed the record with table_count and table_name values as shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you got my point, you can help me with your own approach or correct my approach or&amp;nbsp; you can point me to any document which does this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;test.status_tech:&lt;/U&gt;&lt;/P&gt;
&lt;TABLE width="203"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="125"&gt;table_name&lt;/TD&gt;
&lt;TD width="78"&gt;table_count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Account_Balance&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Customer&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sat, 18 Apr 2020 16:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640966#M190993</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-18T16:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640968#M190994</link>
      <description>&lt;P&gt;Do you need something like the following code does:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
options dlcreatedir;
libname test "%sysfunc(pathname(work))/test";

data test.Account_Balance;
  do i = 1 to 7;
    output;
  end;
run;

data test.Customer;
  do j = 1 to 8;
    output;
  end;
run;

data test.status_tech;
  length table_name $ 41;
  table_name = "Account_Balance"; table_count = .; output;
  table_name = "Customer"; table_count = .; output;
run;

data FileList_1;
  table = "Account_Balance"; output;
  table = "Customer"; output;
run;


options symbolgen mlogic mprint;


%MACRO STATUS_TECH_UPDATE(tab);                                                                                                                                       
   %put &amp;amp;tab; 
   %put "inside macro";
   data _tmp_;
    keep table_count table_name;
    length table_name $ 41;
    table_count = nobs; 
    table_name = "&amp;amp;tab";
    output;
    stop;
    set test.&amp;amp;tab nobs=nobs;
   run;
   proc append base = work.FOR_UPDATE data = _tmp_;
    run;
   proc delete data = _tmp_;
    run;
%MEND;

title "Before";
proc print data = test.status_tech;
run;


/* first iteration */ 
data LD_TABLES_1(keep=table);
  set FileList_1;
  call execute('%nrstr(%STATUS_TECH_UPDATE('||table||')); ');
run;

proc sort data = work.FOR_UPDATE;
  by table_name;
run;
proc sort data = test.status_tech;
  by table_name;
run;

data test.status_tech;
  update test.status_tech work.FOR_UPDATE;
  by table_name;
run;
proc delete data = work.FOR_UPDATE;
run;


title "After first execution";
proc print data = test.status_tech;
run;


/* new records added */
data test.Account_Balance;
  do i = 1 to 17;
    output;
  end;
run;

data test.Customer;
  do j = 1 to 18;
    output;
  end;
run;

/* second iteration */
data LD_TABLES_1(keep=table);
  set FileList_1;
  call execute('%nrstr(%STATUS_TECH_UPDATE('||table||')); ');
run;

proc sort data = work.FOR_UPDATE;
  by table_name;
run;
proc sort data = test.status_tech;
  by table_name;
run;

data test.status_tech;
  update test.status_tech work.FOR_UPDATE;
  by table_name;
run;
proc delete data = work.FOR_UPDATE;
run;

title "After second execution";
proc print data = test.status_tech;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 16:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640968#M190994</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-18T16:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640972#M190996</link>
      <description>Thanks for your code but it's not correct.&lt;BR /&gt;&lt;BR /&gt;How do you tackle if you don't know the number of observations in&lt;BR /&gt;ACCOUNT_BALANCE and CUSTOMER dataset?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Apr 2020 16:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640972#M190996</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-18T16:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640977#M190997</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if the `test` libname is a SAS library then NOBS= is always available, in case test is link to external database you will need regular `select count(1) from &amp;amp;tab.;`&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO STATUS_TECH_UPDATE(tab);                                                                                                                                       
   %put &amp;amp;tab; 
   %put "inside macro";
   
   proc sql;
    create table _tmp_ as
    select 
      "&amp;amp;tab" as table_name length 41
     ,count(1) as table_count
    from test.&amp;amp;tab;
   quit;

   proc append base = work.FOR_UPDATE data = _tmp_;
    run;
   proc delete data = _tmp_;
    run;
%MEND;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 17:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640977#M190997</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-18T17:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640982#M190999</link>
      <description>Thanks. Instead of proc append, can we use proc sql update?&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Apr 2020 17:57:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640982#M190999</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-18T17:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640984#M191000</link>
      <description>&lt;P&gt;That helps a little. But you have not described your input.&amp;nbsp; What dataset is the variable TAB in?&amp;nbsp; Is it always the same dataset?&amp;nbsp; What is it you are counting?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To me it sounds like there is some unnamed dataset, lets call it HAVE, that has a variable named TAB. You want to count the number of observations per value of TAB and insert those counts into a dataset named TEST.STATUS_TECH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's first setup up some actual test data.&amp;nbsp; We will use WORK datasets since we don't have access to your TEST library.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data status_tech;
  length table_name $32 table_count 8;
  input table_name table_count;
cards;
Account_Balance 7
Customer 8
;
data have;
  length tab $32 ;
  input tab @@;
cards;
fred fred sam sam fred sam sam sam 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's count values of TAB and insert into STATUS_TECH.&lt;/P&gt;
&lt;P&gt;You could use SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  insert into status_tech (table_name,table_count)
   select tab,count(*) from have group by tab
 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;                          table_
Obs    table_name          count

 1     Account_Balance       7
 2     Customer              8
 3     fred                  3
 4     sam                   5&lt;/PRE&gt;
&lt;P&gt;If I didn't translate the problem right then please correct. Using your own example input and output datasets. Make sure to post them as code using the Insert SAS Code button in the forum editor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 18:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640984#M191000</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-18T18:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640986#M191001</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO STATUS_TECH_UPDATE(tab);                                                                                                                                       
   %put &amp;amp;tab; 
   %put "inside macro";
   
   proc sql;
   %if %sysfunc(exist(work.FOR_UPDATE)) %then
   %do;
    insert into work.FOR_UPDATE
   %end;
   %else
   %do;
    create table work.FOR_UPDATE as
   %end;
    select 
      "&amp;amp;tab" as table_name length 41
     ,count(1) as table_count
    from test.&amp;amp;tab;
   quit;
%MEND;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 18:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640986#M191001</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-18T18:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640988#M191002</link>
      <description>I would like to correct your understanding.&lt;BR /&gt;&lt;BR /&gt;In your example, fred and sam is a values to the variables 'tab'. Now&lt;BR /&gt;assume fred and sam is some SAS datasets name ,then you have to count the&lt;BR /&gt;observations from  the datasets 'Fred' and 'Sam' and write it to&lt;BR /&gt;test.status_tech.&lt;BR /&gt;&lt;BR /&gt;E.g. test.status_tech should  looks like&lt;BR /&gt;&lt;BR /&gt;Table_name Table_count&lt;BR /&gt;Fred               12&lt;BR /&gt;Sam               44&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Apr 2020 18:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640988#M191002</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-18T18:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640992#M191003</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I would like to correct your understanding.&lt;BR /&gt;&lt;BR /&gt;In your example, fred and sam is a values to the variables 'tab'. Now&lt;BR /&gt;assume fred and sam is some SAS datasets name ,then you have to count the&lt;BR /&gt;observations from the datasets 'Fred' and 'Sam' and write it to&lt;BR /&gt;test.status_tech.&lt;BR /&gt;&lt;BR /&gt;E.g. test.status_tech should looks like&lt;BR /&gt;&lt;BR /&gt;Table_name Table_count&lt;BR /&gt;Fred 12&lt;BR /&gt;Sam 44&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In that case you need to GENERATE code from the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use CALL EXECUTE().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have end=eof;
  if _n_=1 then call execute('proc sql');
  if exist(tab) then call execute(catx(' '
    ,'insert into status_tech (table_name,table_count)'
    ,'select',quote(trim(tab)),',count(*) from ',tab,';'
  ));
  if eof then call execute('quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 19:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/640992#M191003</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-18T19:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/641025#M191014</link>
      <description>Thanks. Any other ways apart from call execute?&lt;BR /&gt;</description>
      <pubDate>Sun, 19 Apr 2020 00:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/641025#M191014</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-04-19T00:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically get the dataset name and count of datasets and update the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/641030#M191015</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can write code to a text file and use %INCLUDE to run it.&amp;nbsp; 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.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to try to figure out macro code then make a macro that takes as input a list of names.&amp;nbsp; &amp;nbsp;Then call it with the list of tables to count.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro counts(tablist);
%local i tab ;
proc sql;
%do i=1 %to %sysfunc(countw(&amp;amp;tablist,%str( )));
  %let tab=%scan(&amp;amp;tablist,&amp;amp;i,%str( ));
  %if %sysfunc(exist(&amp;amp;tab)) %then %do;
insert into status_tech (table_name,table_count) 
  select "&amp;amp;tab",count(*) from &amp;amp;tab
;
  %end;
%end;
quit;
%mend ;
%counts(fred sam);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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(&amp;amp;tablist)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Apr 2020 00:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-get-the-dataset-name-and-count-of-datasets-and/m-p/641030#M191015</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-19T00:20:27Z</dc:date>
    </item>
  </channel>
</rss>

