<?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 SAS Macro: Categorizing a Numerical variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285454#M58364</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for a Macro to catagorize a numeric variable into a catagorical variable by forming groups.&lt;/P&gt;
&lt;P&gt;For example, I have a column called &lt;STRONG&gt;price&lt;/STRONG&gt; and I want to divied it in 10 catagories.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do someone knows such a Macro (Code) ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;Ehsan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jul 2016 10:22:37 GMT</pubDate>
    <dc:creator>ehsanmath</dc:creator>
    <dc:date>2016-07-19T10:22:37Z</dc:date>
    <item>
      <title>SAS Macro: Categorizing a Numerical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285454#M58364</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for a Macro to catagorize a numeric variable into a catagorical variable by forming groups.&lt;/P&gt;
&lt;P&gt;For example, I have a column called &lt;STRONG&gt;price&lt;/STRONG&gt; and I want to divied it in 10 catagories.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do someone knows such a Macro (Code) ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;Ehsan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 10:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285454#M58364</guid>
      <dc:creator>ehsanmath</dc:creator>
      <dc:date>2016-07-19T10:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Catagorizing a Numerical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285457#M58367</link>
      <description>&lt;P&gt;Why do you need a macro. &amp;nbsp;This is data manipulation, should be done in a datastep which is what that is for. &amp;nbsp;Macro is not for this task, it doesn't have the data types or conding structures. &amp;nbsp;If you post example test data (as a datastep) and what the output should look like, I can provide code, but:&lt;/P&gt;
&lt;P&gt;if &amp;lt;&amp;gt; then&lt;/P&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select() when()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could be used, or in fact formats with ranges:&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; value fmt&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 1-10="First"&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 08:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285457#M58367</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-07-19T08:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Catagorizing a Numerical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285459#M58368</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use proc format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data prices;&lt;BR /&gt;input item $ price;&lt;BR /&gt;cards;&lt;BR /&gt;a 2&lt;BR /&gt;b 50&lt;BR /&gt;c 123&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;value price low-&amp;lt;10="cheap"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10-&amp;lt;50="ok"&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;50-high="expensive";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data=prices;&lt;BR /&gt;format price price.;&lt;BR /&gt;var item price;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 08:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285459#M58368</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-07-19T08:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Catagorizing a Numerical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285460#M58369</link>
      <description>&lt;P&gt;It depend on the rule how you category this price .&lt;/P&gt;
&lt;P&gt;Check PROC RANK + groups=10 option .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc rank data=have out=want groups=10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;var price;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;ranks rank_price;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 08:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285460#M58369</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-19T08:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Catagorizing a Numerical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285476#M58377</link>
      <description>&lt;P&gt;Actually, I am looking for an Automated (Macro) solution of this problem.&lt;/P&gt;
&lt;P&gt;I habe more than 400 numeric columns with numeric values having different ranges (min max mean etc) .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I need a Macro that takes as Input a Dataset and variable name and automatically make N groups(catagories) out of this column without puting manual effort as you guys have already suggested above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So do someone knows an automated solution of this problem ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ehsan&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 09:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285476#M58377</guid>
      <dc:creator>ehsanmath</dc:creator>
      <dc:date>2016-07-19T09:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Catagorizing a Numerical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285536#M58399</link>
      <description>&lt;P&gt;Assuming you want to categorize all columns of your dataset, otherwise you have to&lt;/P&gt;
&lt;P&gt;refine the SQL query.&lt;/P&gt;
&lt;P&gt;I use Ksharp's solution, proc rank, which I didnt know of. It is only slightly adapted to&lt;/P&gt;
&lt;P&gt;automatically generate the variables and ranks names.&lt;/P&gt;
&lt;P&gt;Here the source dataset's name is "prices"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
SELECT NAME, cats("RANK_",NAME)
INTO :cols SEPARATED BY ' ',
     :ranks SEPARATED BY ' '
FROM dictionary.columns
WHERE LIBNAME="WORK" AND MEMNAME="PRICES" /* AND other restrictions */; /* /!\ use upper case here */
quit;

proc rank data=prices out=want groups=10;
var &amp;amp;cols.;
ranks &amp;amp;ranks.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jul 2016 14:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285536#M58399</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-07-19T14:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Macro: Catagorizing a Numerical variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285776#M58489</link>
      <description>&lt;P&gt;Actually I was looking for ready-made solution. Its sounds like that there is now such known solution available. So I have to put the Ideas given by you guys in a code.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 08:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Categorizing-a-Numerical-variable/m-p/285776#M58489</guid>
      <dc:creator>ehsanmath</dc:creator>
      <dc:date>2016-07-20T08:07:47Z</dc:date>
    </item>
  </channel>
</rss>

