<?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: Determining number of variables in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85476#M18351</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can request that from the dictionary tables. For example to find out how many variables are in sashelp.class&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc sql; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select nvar &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from dictionary.tables &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where libname='SASHELP' and memname='CLASS'; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPPER case is important for the library name and the dataset name (memname variable) as these are stored as upper case in the dictionary tables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 24 May 2013 14:28:35 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2013-05-24T14:28:35Z</dc:date>
    <item>
      <title>Determining number of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85475#M18350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I receive Excel files from clients, and these will have varying numbers of variables (columns) each time. After importing to SAS, I wish to automatically determine the number of variables in a dataset so I can set up the index for array processing. I know the SET command has NOBS, but is there nothing similar for number of variables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 14:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85475#M18350</guid>
      <dc:creator>dmorrell</dc:creator>
      <dc:date>2013-05-24T14:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Determining number of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85476#M18351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can request that from the dictionary tables. For example to find out how many variables are in sashelp.class&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc sql; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select nvar &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from dictionary.tables &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where libname='SASHELP' and memname='CLASS'; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UPPER case is important for the library name and the dataset name (memname variable) as these are stored as upper case in the dictionary tables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 14:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85476#M18351</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-05-24T14:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Determining number of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85477#M18352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In addition to the dictionary tables, you can open the attributes of the data set in a DATA Step.&lt;/P&gt;&lt;P&gt;If you are going to work with arrays, you may want to separate the character from the numeric variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is sample code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let indsn=sashelp.class;&lt;/P&gt;&lt;P&gt;data _NULL_;&lt;BR /&gt;length varnme $32 varClst varNlst $32767;&lt;BR /&gt;dsid = open("&amp;amp;indsn");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* open data set attributes */&lt;BR /&gt;vars = attrn(dsid,"NVARS");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* get number of variables */&lt;BR /&gt;do i = 1 to vars;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* go through variable names */&lt;BR /&gt;&amp;nbsp; varnme = varname (dsid, i);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* name of variable */&lt;BR /&gt;&amp;nbsp; vartype = vartype(dsid,i);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Character or numeric? */&lt;BR /&gt;&amp;nbsp; if vartype = "C" then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; varClst = catx(' ',varClst,varnme);&lt;BR /&gt;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; varNlst = catx(' ',varNlst,varnme);&lt;BR /&gt;end;&lt;BR /&gt;cntC = count(strip(varClst),' ') + 1;&lt;BR /&gt;cntN = count(strip(varNlst),' ') + 1;&lt;BR /&gt;call symputx('varClst',varClst);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* put variable list in macro variable */&lt;BR /&gt;call symputx('varNlst',varNlst);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* put variable list in macro variable */&lt;BR /&gt;call symputx('varCcnt',cntC);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* put variable count in macro variable */&lt;BR /&gt;call symputx('varNcnt',cntN);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* put variable count in macro variable */&lt;BR /&gt;rc = close(dsid);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* close data set attributes */&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%put _user_;&amp;nbsp;&amp;nbsp; /* verify existence of macro variables */&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 15:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85477#M18352</guid>
      <dc:creator>jwsquillace</dc:creator>
      <dc:date>2013-05-24T15:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determining number of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85478#M18353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your data step compiler already has the infirmation for you so you shouldn't need and preparatory steps at all;-)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;use _character_ and _numeric_ as variable lists to populate arrays&amp;nbsp; and you'll have all you need.&lt;/P&gt;&lt;P&gt;data action;&lt;/P&gt;&lt;P&gt;Set your.dataset ;&lt;/P&gt;&lt;P&gt;Array nums(*) _numeric_ ;&lt;/P&gt;&lt;P&gt;array chrs(*) _character_ ;&lt;/P&gt;&lt;P&gt;number_of_numerics = dim( nums );&lt;/P&gt;&lt;P&gt;number_of_charvars = dim( chrs );&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 May 2013 08:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85478#M18353</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-05-25T08:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Determining number of variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85479#M18354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dmorrell,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think use SASHELP to the maximum instead of using these heavy codes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once you import Excel file into sas then use SASHELP tables namely Dictionary.tables or sashelp.VTable to obtain every information about every element in the datasets present or user created.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2013 06:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-number-of-variables-in-a-dataset/m-p/85479#M18354</guid>
      <dc:creator>NishunkSaxena</dc:creator>
      <dc:date>2013-05-29T06:30:39Z</dc:date>
    </item>
  </channel>
</rss>

