<?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 Distinguishing character variables from numeric variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distinguishing-character-variables-from-numeric-variables/m-p/735614#M229162</link>
    <description>&lt;P&gt;I have a dataset with 500 variables. I want to run proc freq and proc means for the character and numeric variables. SAS is great in handling _character_ and _numeric_ variables; however, the character variables in my dataset are coded as numeric because each character variable is a couple of levels that are saved with numbers (e.g., 1,2,3,4 then I have format to assign the character description in the output). Usually, I manually separate the character variables. I wonder if you have a suggestion to write a code to help me with&amp;nbsp;distinguishing the character variables from the numeric variables. Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 20 Apr 2021 15:26:24 GMT</pubDate>
    <dc:creator>Emma_at_SAS</dc:creator>
    <dc:date>2021-04-20T15:26:24Z</dc:date>
    <item>
      <title>Distinguishing character variables from numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinguishing-character-variables-from-numeric-variables/m-p/735614#M229162</link>
      <description>&lt;P&gt;I have a dataset with 500 variables. I want to run proc freq and proc means for the character and numeric variables. SAS is great in handling _character_ and _numeric_ variables; however, the character variables in my dataset are coded as numeric because each character variable is a couple of levels that are saved with numbers (e.g., 1,2,3,4 then I have format to assign the character description in the output). Usually, I manually separate the character variables. I wonder if you have a suggestion to write a code to help me with&amp;nbsp;distinguishing the character variables from the numeric variables. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 15:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinguishing-character-variables-from-numeric-variables/m-p/735614#M229162</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-04-20T15:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Distinguishing character variables from numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinguishing-character-variables-from-numeric-variables/m-p/735622#M229165</link>
      <description>&lt;P&gt;You could just define those variables as character when you create them.&amp;nbsp; So instead of defining those variables with values of 1 and 2 as numeric define then as character with values of '1' and '2' and create character formats instead of numeric formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What form does your original data come in?&amp;nbsp; If it is text file (like a CSV file) then just adjust the code of your data step that is reading it to define them as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds like you want to distinguish the categorical variables from the continuous (or at least multi level)&amp;nbsp; variables whether or not the variables are defined as character.&amp;nbsp; The NLEVEL output of PROC FREQ is very useful for this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output nlevels=nlevels;
proc freq nlevels data=have ;
  tables _all_ / noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then set some upper limit on the number of levels below which you want to consider the variable as categorical.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nliteral(TableVar) into :varlist separated by ' '
  from nlevels 
  where nlevels &amp;lt; 5 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use that list of variables in your other code.&amp;nbsp; For example you might use that list as which variable to generate PROC FREQ tables for.&amp;nbsp; Or perhaps to exclude them from PROC MEANS analysis of the numeric variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have ;
  tables &amp;amp;varlist;
run;
proc means data=have(drop=&amp;amp;varlist);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 15:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinguishing-character-variables-from-numeric-variables/m-p/735622#M229165</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-20T15:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Distinguishing character variables from numeric variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinguishing-character-variables-from-numeric-variables/m-p/735745#M229195</link>
      <description>Thank you, Tom. This is brilliant! &lt;BR /&gt;Thank you, Reeza, for your thumbs up!</description>
      <pubDate>Tue, 20 Apr 2021 20:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinguishing-character-variables-from-numeric-variables/m-p/735745#M229195</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2021-04-20T20:05:13Z</dc:date>
    </item>
  </channel>
</rss>

