<?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: Row by Row operation in a dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534844#M6382</link>
    <description>&lt;P&gt;This is not because the accepted solution is not fine.&lt;/P&gt;
&lt;P&gt;I just found an opportunity to try out a perfect example of using the DOSUBL function&amp;nbsp;&lt;img id="smileylol" class="emoticon emoticon-smileylol" src="https://communities.sas.com/i/smilies/16x16_smiley-lol.png" alt="Smiley LOL" title="Smiley LOL" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro countobs(table);
  %global rows;
  %let rows=0;
  proc sql noprint;
    select count(*) format=12. into : rows trimmed
    from &amp;amp;table. ;
  quit;
%mend;

data tables;
  length table $41;
  input table;
  rc = dosubl(catt('%countobs(', table, ' )') );
  rows = input(symget('rows'),12.);
  drop rc;
  cards;
sashelp.class
sashelp.cars
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Feb 2019 14:01:56 GMT</pubDate>
    <dc:creator>MichaelLarsen</dc:creator>
    <dc:date>2019-02-12T14:01:56Z</dc:date>
    <item>
      <title>Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534645#M6357</link>
      <description>&lt;P&gt;I have a dataset ""table_names which contains table names / dataset names.&lt;/P&gt;&lt;P&gt;I want to take each table name at a time and count the number of rows in that table and display.&lt;/P&gt;&lt;P&gt;Here is the example of my table.&lt;/P&gt;&lt;P&gt;DATA table_names;&lt;BR /&gt;length name $32 ;&lt;BR /&gt;input name;&lt;BR /&gt;DATALINES ;&lt;BR /&gt;tablea&lt;BR /&gt;tableb&lt;BR /&gt;tablec&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want result like this assuming that tablea has 30 rows, tableb has 45 rows and tablec has 50 rows:&lt;/P&gt;&lt;P&gt;name rowcount&lt;/P&gt;&lt;P&gt;tablea 30&lt;/P&gt;&lt;P&gt;tableb 45&lt;/P&gt;&lt;P&gt;tablec 50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 22:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534645#M6357</guid>
      <dc:creator>bhu</dc:creator>
      <dc:date>2019-02-11T22:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534650#M6358</link>
      <description>Are these SAS data sets? Are they in a single library or multilple libraries? &lt;BR /&gt;&lt;BR /&gt;There are a set of tables, dictionary tables, that hold this type of data so it's super easy to query that table. The table for this would be sashelp.vtable.</description>
      <pubDate>Mon, 11 Feb 2019 23:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534650#M6358</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-11T23:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534652#M6359</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data tablea tableb tablec;
x='blahblah';
run;




DATA table_names;
length name $32 ;
input name;
DATALINES ;
tablea
tableb
tablec
;
RUN;


data want;
if _n_=1 then do;
if 0 then set sashelp.vtable(keep=memname nobs);
   dcl hash H (dataset:"sashelp.vtable(keep=libname memname nobs where=(libname='WORK'))") ;
   h.definekey  ("memname") ;
   h.definedata ("memname","nobs") ;
   h.definedone () ;
   end;
set table_names;
if h.find(key:upcase(name))=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2019 23:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534652#M6359</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-11T23:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534655#M6360</link>
      <description>&lt;P&gt;The datasets are not SAS datasets, they are sql tables. I am accessing sql tables through sas and counting them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 23:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534655#M6360</guid>
      <dc:creator>bhu</dc:creator>
      <dc:date>2019-02-11T23:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534657#M6361</link>
      <description>&lt;P&gt;with SAS access lib-name engine, you can treat the db tables as datasets and play with hashes&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 23:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534657#M6361</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-11T23:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534660#M6362</link>
      <description>Which DB? Can you hit their dictionary tables? Otherwise, the solution is to write a small macro that counts each file and appends it to a dataset. You can then use CALL EXECUTE to run the macro multiple times.</description>
      <pubDate>Mon, 11 Feb 2019 23:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534660#M6362</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-11T23:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534661#M6363</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222166"&gt;@bhu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The datasets are not SAS datasets, they are sql tables. I am accessing sql tables through sas and counting them.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you have SAS/Access to use those tables?&lt;/P&gt;
&lt;P&gt;Many DBMS have their own set of tables containing meta data and you may be able to query the source database(s) about the properties of data tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 23:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534661#M6363</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-11T23:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534662#M6364</link>
      <description>&lt;P&gt;This can get you started. You'll likely need to make changes to account for a library reference or change how the names are passed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a macro that counts the number of records in a single data set&lt;/P&gt;
&lt;P&gt;2. Append that into master data set&lt;/P&gt;
&lt;P&gt;3. Drop temporary tables&lt;/P&gt;
&lt;P&gt;4. Run for each table in list&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this will create it into a table called myRecs. You can customize that name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;*macro to count the number of records;
%macro countRecs(tableName= , dset=);

proc sql noprint;
create table _temp as
select "&amp;amp;tableName" as tableName length=32, count(*) as nRecs
from &amp;amp;tableName;
quit;

proc append base=&amp;amp;dset data=_temp;
run;

%*drop table to avoid errors;
proc sql noprint;
drop table _temp;
quit;

%mend;

*data set with list of table names;
data demo;
input tableName $32.;
cards;
sashelp.class
sashelp.cars
sashelp.heart
;
run;

*run macro for each data set name;
data run;
set demo;

*creates string that looks like macro call;
str = catt('%countRecs(tableName=', tableName, ', dset=Myrecs);');
call execute(str);

run;



&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222166"&gt;@bhu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset ""table_names which contains table names / dataset names.&lt;/P&gt;
&lt;P&gt;I want to take each table name at a time and count the number of rows in that table and display.&lt;/P&gt;
&lt;P&gt;Here is the example of my table.&lt;/P&gt;
&lt;P&gt;DATA table_names;&lt;BR /&gt;length name $32 ;&lt;BR /&gt;input name;&lt;BR /&gt;DATALINES ;&lt;BR /&gt;tablea&lt;BR /&gt;tableb&lt;BR /&gt;tablec&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want result like this assuming that tablea has 30 rows, tableb has 45 rows and tablec has 50 rows:&lt;/P&gt;
&lt;P&gt;name rowcount&lt;/P&gt;
&lt;P&gt;tablea 30&lt;/P&gt;
&lt;P&gt;tableb 45&lt;/P&gt;
&lt;P&gt;tablec 50&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 23:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534662#M6364</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-11T23:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534664#M6365</link>
      <description>This works fine for sas datasets inside the WORK library. Changing the libname to SQL, shows 0 rows for all tables in sashelp.vtable.</description>
      <pubDate>Mon, 11 Feb 2019 23:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534664#M6365</guid>
      <dc:creator>bhu</dc:creator>
      <dc:date>2019-02-11T23:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534670#M6366</link>
      <description>&lt;P&gt;Thank you all for replying and get the solution.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 00:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534670#M6366</guid>
      <dc:creator>bhu</dc:creator>
      <dc:date>2019-02-12T00:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Row by Row operation in a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534844#M6382</link>
      <description>&lt;P&gt;This is not because the accepted solution is not fine.&lt;/P&gt;
&lt;P&gt;I just found an opportunity to try out a perfect example of using the DOSUBL function&amp;nbsp;&lt;img id="smileylol" class="emoticon emoticon-smileylol" src="https://communities.sas.com/i/smilies/16x16_smiley-lol.png" alt="Smiley LOL" title="Smiley LOL" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro countobs(table);
  %global rows;
  %let rows=0;
  proc sql noprint;
    select count(*) format=12. into : rows trimmed
    from &amp;amp;table. ;
  quit;
%mend;

data tables;
  length table $41;
  input table;
  rc = dosubl(catt('%countobs(', table, ' )') );
  rows = input(symget('rows'),12.);
  drop rc;
  cards;
sashelp.class
sashelp.cars
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Feb 2019 14:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Row-by-Row-operation-in-a-dataset/m-p/534844#M6382</guid>
      <dc:creator>MichaelLarsen</dc:creator>
      <dc:date>2019-02-12T14:01:56Z</dc:date>
    </item>
  </channel>
</rss>

