<?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 tell column numeric or not?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936056#M367970</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Any function to tell a column at a dataset is numeric or not?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading in files, but some columns are numbers but are readin as char.&lt;/P&gt;
&lt;P&gt;So need a macro take dataset name and column name 1) tells numeric or not 2) if not, simple to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;change the data format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Such programs have been written.&amp;nbsp; Here is one&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/varexist.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/varexist.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could use that macro to find the TYPE of the vairable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put AGE in SASHELP.CLASS is %varexist(sashelp.class,age,type);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you might want to take a step back and find out why the variable was not created properly.&amp;nbsp; Where did the dataset in question come from?&amp;nbsp; How did it get into SAS?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2024 15:23:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-07-17T15:23:33Z</dc:date>
    <item>
      <title>how to tell column numeric or not?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936021#M367959</link>
      <description>&lt;P&gt;Any function to tell a column at a dataset is numeric or not?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading in files, but some columns are numbers but are readin as char.&lt;/P&gt;
&lt;P&gt;So need a macro take dataset name and column name 1) tells numeric or not 2) if not, simple to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;change the data format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 12:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936021#M367959</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2024-07-17T12:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to tell column numeric or not?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936023#M367960</link>
      <description>&lt;P&gt;PROC CONTENTS will tell you (and there are other ways as well)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=sashelp.class;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1721218443247.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98452i20AF61DAD5093B56/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PaigeMiller_0-1721218443247.png" alt="PaigeMiller_0-1721218443247.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;So need a macro take dataset name and column name 1) tells numeric or not 2) if not, simple to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;change the data format.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not a "format" issue, it is a variable type issue. In general, if the column is not numeric, you can't convert it to numeric unless it contains only digits (and perhaps a single decimal point and perhaps a single minus sign at the start of the text string). You can't convert these two character variables to numeric. So what do you really want here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 12:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936023#M367960</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-17T12:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to tell column numeric or not?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936050#M367968</link>
      <description>&lt;P&gt;One way to query specific data set properties:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   select name, type 
   from dictionary.columns
   where libname='SASHELP' and memname='CLASS' 
      and upcase(name)='SEX'
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Libname and memname (dataset/view /etc ) are stored in uppercase. If you have more than datasets in your libarary you may need to add " and memtype='DATA' ".&lt;/P&gt;
&lt;P&gt;The names of the variables may not be of consistent case so address that with one of the case functions.&lt;/P&gt;
&lt;P&gt;If you have a list of variables to check then use something like: " upcase(name) in ('VAR1' 'VARNAME2' 'OTHERVARNAME')".&lt;/P&gt;
&lt;P&gt;Or skip the name entirely essentially duplicating Proc Contents output...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or look at the documentation of the VARTYPE function as an alternate.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 14:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936050#M367968</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-17T14:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to tell column numeric or not?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936055#M367969</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading in files, but some columns are numbers but are readin as char.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you can fix it while you read in the data that's preferable than fixing after the fact. In the odd case you read in a variable as numeric instead of character you would lose information. If all files are the same layout using a data step to read rather than proc import will help to standardize the read in and fix it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 15:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936055#M367969</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-07-17T15:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to tell column numeric or not?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936056#M367970</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Any function to tell a column at a dataset is numeric or not?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading in files, but some columns are numbers but are readin as char.&lt;/P&gt;
&lt;P&gt;So need a macro take dataset name and column name 1) tells numeric or not 2) if not, simple to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;change the data format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Such programs have been written.&amp;nbsp; Here is one&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/varexist.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/varexist.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could use that macro to find the TYPE of the vairable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put AGE in SASHELP.CLASS is %varexist(sashelp.class,age,type);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you might want to take a step back and find out why the variable was not created properly.&amp;nbsp; Where did the dataset in question come from?&amp;nbsp; How did it get into SAS?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 15:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936056#M367970</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-17T15:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to tell column numeric or not?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936062#M367971</link>
      <description>Thanks all, The macro should work out well.</description>
      <pubDate>Wed, 17 Jul 2024 16:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-tell-column-numeric-or-not/m-p/936062#M367971</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2024-07-17T16:43:49Z</dc:date>
    </item>
  </channel>
</rss>

