<?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: Finding numeric Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28890#M5397</link>
    <description>I'm sure that all of those methods -would- work, But I'm not sure I'd use or recommend anything but the DICTIONARY or SASHELP method. OK, maybe the PROC CONTENTS method. &lt;BR /&gt;
&lt;BR /&gt;
But I would never use the PROC MEANS or the DATA step methods -- for one thing, I usually teach beginners and using PROC MEANS without a VAR statement -could- get them into bad habits of MEANS usage, when the other two methods work quite well. And for my students, ARRAY usage is generally beyond their level -and- unnecesary, when the DICTIONARY.TABLES or SASHELP or PROC CONTENTS methods work so well, and so simply.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Thu, 10 Dec 2009 20:27:26 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2009-12-10T20:27:26Z</dc:date>
    <item>
      <title>Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28885#M5392</link>
      <description>Let's say you want a list of all the numeric variables in a data set.  There are several ways you could do it, including running&lt;BR /&gt;
&lt;BR /&gt;
* a proc contents with an out option, then filter out the type=1 (numeric) variables&lt;BR /&gt;
* proc means with no VAR statement and an OUTPUT statement.&lt;BR /&gt;
* a data step with obs=1 and iterating over an array&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
    set sashelp.class(obs=1);&lt;BR /&gt;
	array s{*} _numeric_;&lt;BR /&gt;
	do i = 1 to dim(s);&lt;BR /&gt;
	   n = vname(s{i});&lt;BR /&gt;
	   put n;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Are there others?  What is your favorite method?   The proc means method is unsuitable for very large data sets, but does give the sample means as additional info.</description>
      <pubDate>Thu, 10 Dec 2009 19:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28885#M5392</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2009-12-10T19:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28886#M5393</link>
      <description>ps. I usually indent my code, but the browser removed all my spaces.  Forgive me!</description>
      <pubDate>Thu, 10 Dec 2009 19:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28886#M5393</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2009-12-10T19:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28887#M5394</link>
      <description>Hi:&lt;BR /&gt;
  I'd use SASHELP or DICTIONARY tables. See below.&lt;BR /&gt;
&lt;BR /&gt;
  Also, for future reference, refer to this posting for how to use [pre] and [/pre]  to preserve indentation:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=27609毙" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=27609毙&lt;/A&gt; &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
                        &lt;BR /&gt;
** 1) Create table, but could just print from SQL;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table structure as&lt;BR /&gt;
  select libname, memname, name, type, length, &lt;BR /&gt;
         format, informat, label&lt;BR /&gt;
  from dictionary.columns&lt;BR /&gt;
  where libname = 'SASHELP' and &lt;BR /&gt;
        memname = 'SHOES' and&lt;BR /&gt;
        upcase(type) = 'NUM';&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
                        &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=work.structure;&lt;BR /&gt;
  title '1) Use DICTIONARY.COLUMNS';&lt;BR /&gt;
run; &lt;BR /&gt;
                   &lt;BR /&gt;
** 2) Just print directly from SASHELP.VCOLUMN;&lt;BR /&gt;
PROC PRINT data=sashelp.vcolumn;&lt;BR /&gt;
  title '2) Use SASHELP.VCOLUMN';&lt;BR /&gt;
  where libname = 'SASHELP' and &lt;BR /&gt;
        memname = 'SHOES' and&lt;BR /&gt;
        upcase(type) = 'NUM';&lt;BR /&gt;
  var libname memname name type length format informat label;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 10 Dec 2009 19:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28887#M5394</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-12-10T19:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28888#M5395</link>
      <description>Thanks!  I had forgotten that method, and I actually had used it in my code, now that I think of it.</description>
      <pubDate>Thu, 10 Dec 2009 19:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28888#M5395</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2009-12-10T19:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28889#M5396</link>
      <description>So, now we have four methods&lt;BR /&gt;
&lt;BR /&gt;
* a proc contents with an out option, then filter out the type=1 (numeric) variables&lt;BR /&gt;
* proc means with no VAR statement and an OUTPUT statement.&lt;BR /&gt;
* a data step with obs=1 and iterating over an array&lt;BR /&gt;
* Dictionary (and equivalently SASHELP) tables.</description>
      <pubDate>Thu, 10 Dec 2009 19:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28889#M5396</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2009-12-10T19:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28890#M5397</link>
      <description>I'm sure that all of those methods -would- work, But I'm not sure I'd use or recommend anything but the DICTIONARY or SASHELP method. OK, maybe the PROC CONTENTS method. &lt;BR /&gt;
&lt;BR /&gt;
But I would never use the PROC MEANS or the DATA step methods -- for one thing, I usually teach beginners and using PROC MEANS without a VAR statement -could- get them into bad habits of MEANS usage, when the other two methods work quite well. And for my students, ARRAY usage is generally beyond their level -and- unnecesary, when the DICTIONARY.TABLES or SASHELP or PROC CONTENTS methods work so well, and so simply.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 10 Dec 2009 20:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28890#M5397</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-12-10T20:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28891#M5398</link>
      <description>In our server environment, dictionary tables take a disproportionately long time to populate since the each query on those views take a while to search through the entire environment.&lt;BR /&gt;
&lt;BR /&gt;
On my local machine, dictionary tables are my favorite, followed by the CONTENTS procedure.   I see your point about arrays being superfluous when the dictionary tables are available.

Message was edited by: mftuchman</description>
      <pubDate>Thu, 10 Dec 2009 21:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28891#M5398</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2009-12-10T21:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28892#M5399</link>
      <description>sashelp.vcolumn should be no slower than dictionary.columns IF you use it in the SQL procedure.&lt;BR /&gt;
I offer 2 more ways to work with variable or column names as data:&lt;BR /&gt;
proc transpose data= sashelp.class( obs= 1);&lt;BR /&gt;
proc print; run;&lt;BR /&gt;
and, well demonstrated by dat _null_ (the poster not the code)&lt;BR /&gt;
call vnext()&lt;BR /&gt;
Probably all techniques have their place. We just have to understand when one is more suitable than the others.&lt;BR /&gt;
 &lt;BR /&gt;
another $0.02 from&lt;BR /&gt;
PeterC&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
.</description>
      <pubDate>Fri, 11 Dec 2009 08:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28892#M5399</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-12-11T08:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28893#M5400</link>
      <description>As Peter mentioned PROC TRANSPOSE is another canidate although I usually run it with OBS=0 so I don't create any COLn variables.  &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc transpose data=sashelp.shoes(obs=0 /*drop=_numeric_*/) out=numlist;&lt;BR /&gt;
   *var _numeric_; *or no var statement;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
I use similar PROC TRANSPOSE's to "expand" all sorts variable list macro variables, when writing dynamic programs.  The advantage is that I can expand the list of words that may also contain a "SAS Variable List" such as A1-A10,  AB: or double dashed lists, etc.  &lt;BR /&gt;
&lt;BR /&gt;
Plus if a variable does not exist then I get an nice error and message and I can examine the value of &amp;amp;SYSRC, I think that's the one, and stop the program or take other appropiate action.&lt;BR /&gt;
&lt;BR /&gt;
As for PROC MEANS adding the data set opion OBS=1 would fix the data size problem, but I prefer PROC TRANPOSE.</description>
      <pubDate>Fri, 11 Dec 2009 15:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28893#M5400</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-12-11T15:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28894#M5401</link>
      <description>I found this very impressive.   Useful tip!   I think this is a favorite so far, particularly because we can use OBS=0 to pull the result.&lt;BR /&gt;
&lt;BR /&gt;
The reason I originally use PROC MEANS is that I have to eventually report the means anyway.  But I think this wins a prize for elegance.

Message was edited by: mftuchman</description>
      <pubDate>Fri, 11 Dec 2009 16:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28894#M5401</guid>
      <dc:creator>mftuchman</dc:creator>
      <dc:date>2009-12-11T16:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Finding numeric Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28895#M5402</link>
      <description>data _null_;&lt;BR /&gt;
        dsid = open("sashelp.class");&lt;BR /&gt;
        if dsid = 0 then stop;&lt;BR /&gt;
        nvars = attrn(dsid,"nvars");&lt;BR /&gt;
        do i = 1 to nvars;&lt;BR /&gt;
                if vartype(dsid,i) = "N" then &lt;BR /&gt;
                        do;&lt;BR /&gt;
                                varname = varname(dsid,i);&lt;BR /&gt;
                                put varname =;&lt;BR /&gt;
                        end;&lt;BR /&gt;
        end;&lt;BR /&gt;
        rc = close(dsid);&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 16 Dec 2009 12:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-numeric-Variables/m-p/28895#M5402</guid>
      <dc:creator>SAS_user</dc:creator>
      <dc:date>2009-12-16T12:00:10Z</dc:date>
    </item>
  </channel>
</rss>

