<?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: How to count variables for each dataset in a library in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727587#M226321</link>
    <description>Using macros to get required result</description>
    <pubDate>Thu, 18 Mar 2021 22:12:58 GMT</pubDate>
    <dc:creator>BrahmanandaRao</dc:creator>
    <dc:date>2021-03-18T22:12:58Z</dc:date>
    <item>
      <title>How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727402#M226226</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select catx("-",memname,nvar) into: x separated by ","
from dictionary.columns
where libname='FIRST' and memtype="DATA";
quit;&lt;BR /&gt;&lt;BR /&gt;%put&amp;nbsp;&amp;amp;x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want all variables for each dataset in FIRST libraray&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 13:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727402#M226226</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2021-03-18T13:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727404#M226227</link>
      <description>&lt;P&gt;What is wrong with the code you show?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 13:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727404#M226227</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-18T13:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727407#M226228</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anandkvn_0-1616075621562.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56105i02E9133FF4343114/image-size/large?v=v2&amp;amp;px=999" role="button" title="Anandkvn_0-1616075621562.png" alt="Anandkvn_0-1616075621562.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 13:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727407#M226228</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2021-03-18T13:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727408#M226229</link>
      <description>&lt;P&gt;NVAR is not a variable in DICTIONARY.COLUMNS.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;What are you trying to do by using this non-existent NVAR variable?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 13:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727408#M226229</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-18T13:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727410#M226231</link>
      <description>&lt;P&gt;Since you are retrieving one observation per variable just use GROUP BY and COUNT(*).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
  select catx("-",memname,count(*))
    into :x separated by ","
  from dictionary.columns
  where libname='WORK' and memtype="DATA"
  group by memname
  ;
quit;
%put &amp;amp;=sqlobs &amp;amp;=x ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Mar 2021 14:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727410#M226231</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-18T14:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727420#M226239</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anandkvn_0-1616075621562.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56105i02E9133FF4343114/image-size/large?v=v2&amp;amp;px=999" role="button" title="Anandkvn_0-1616075621562.png" alt="Anandkvn_0-1616075621562.png" /&gt;&lt;/span&gt;&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;
&lt;P&gt;NVAR is in Dictionary.Tables not Dictionary.Columns. Each entry in Dictionary.columns is a single variable, so the "number"&lt;/P&gt;
&lt;P&gt;would always be 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I shudder to think just what you intend to do with such a macro variable.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 14:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727420#M226239</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-18T14:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727442#M226247</link>
      <description>&lt;P&gt;If you do a search of this topic on here you'll find another little nifty macro like the one I linked you to yesterday that creates a code book or documents all the metadata for your tables in a nice form, with many options for customization.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 15:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727442#M226247</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-18T15:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727451#M226251</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your question is "&lt;STRONG&gt;How to count variables for each dataset in a library&lt;/STRONG&gt;".&lt;BR /&gt;While there are many approaches to the solution, I would use the following code which I find simple and pretty straight forward.&amp;nbsp;&lt;BR /&gt;I hope you will find it useful.&lt;BR /&gt;It creates two column output, the first is name of the dataset and the second the number of columns in the table.&lt;BR /&gt;Here is the code.&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select memname Label "Dataset" ,count(name) as Num_of_cols&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where memtype="DATA"&lt;BR /&gt;group by memname ;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 15:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727451#M226251</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-03-18T15:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727462#M226261</link>
      <description>&lt;P&gt;It seems you wat to select from dictionary.tables and not dictionary.columns.&lt;/P&gt;
&lt;P&gt;Run next code for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select memname, nvar
   from dictionary.tables
   where libname = "SASHELP";
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>Thu, 18 Mar 2021 16:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727462#M226261</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-18T16:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727587#M226321</link>
      <description>Using macros to get required result</description>
      <pubDate>Thu, 18 Mar 2021 22:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727587#M226321</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2021-03-18T22:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727606#M226330</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;, your subject is "&lt;SPAN&gt;How to &lt;STRONG&gt;count&lt;/STRONG&gt; variables for each dataset in a library&lt;/SPAN&gt;".&lt;/P&gt;
&lt;P&gt;You can covert the code I sent to a macro in order to get the information for any desired dataset in a given library:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro count(lib=,dsname=);
  proc sql;
    select memname, nvar
   from dictionary.tables
   where libname = %upcase("&amp;amp;lib") and
               memname = %upcase("&amp;amp;dsname");
 quit;
%mend count;
%count(lib=sashelp, dsname=class); /* this is an example of using the macro */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 00:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727606#M226330</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-19T00:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to count variables for each dataset in a library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727612#M226336</link>
      <description>&lt;P&gt;What kind of result you expect? &lt;BR /&gt;If you prefer a macro-variable then:&lt;BR /&gt;%macro count(lib=,dsname=);&lt;BR /&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;%global nvar;&lt;BR /&gt;select nvar into :nvar&lt;BR /&gt;from dictionary.tables&lt;BR /&gt;where libname = %upcase("&amp;amp;lib") and&lt;BR /&gt;memname = %upcase("&amp;amp;dsname");&lt;BR /&gt;quit;&lt;BR /&gt;%mend count;&lt;BR /&gt;%count(lib=sashelp, dsname=class);&lt;BR /&gt;%put NVAR=&amp;amp;nvar;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 00:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-variables-for-each-dataset-in-a-library/m-p/727612#M226336</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-19T00:52:46Z</dc:date>
    </item>
  </channel>
</rss>

