<?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 create a composite categorical variable from other ordinal variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361913#M274784</link>
    <description>&lt;TABLE width="279"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="95"&gt;
&lt;P&gt;Quintile of Na&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="92"&gt;Quintile of K&lt;/TD&gt;
&lt;TD width="92"&gt;NaKgroup&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;13&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;14&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;24&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data looks as the table above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 variables which are quintiles of Na and K (so each of them has 5 levels: 1st, 2nd,...5th quintile).&lt;/P&gt;
&lt;P&gt;Now I want to create new var as NaKgroup which combines those 2 quintiles variables. This new variable will have 25 categories.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 May 2017 10:02:42 GMT</pubDate>
    <dc:creator>Minhtrang</dc:creator>
    <dc:date>2017-05-26T10:02:42Z</dc:date>
    <item>
      <title>How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361902#M274781</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I have 2 ordinal variables (quintiles).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I want to create a new categorical variable which combine all levels of those ordinal ones.&lt;/P&gt;
&lt;P&gt;So my new var will have 25 categories.&lt;/P&gt;
&lt;P&gt;Using if statement is really not a good solution.&lt;/P&gt;
&lt;P&gt;Could&amp;nbsp;anyone help me out with some tricks?&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 08:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361902#M274781</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2017-05-26T08:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361905#M274782</link>
      <description>&lt;P&gt;Please reveiw the guidance found underneath the Post button on post a new question:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9078i5346FC9F68077DBF/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without anything to work with I can't really say anything.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 08:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361905#M274782</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-26T08:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361906#M274783</link>
      <description>&lt;P&gt;Could you please present the sample data and the expected categorical output. This will help to get better response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe using the format we could create the categorical variables, but a sample data will help me to confirm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 08:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361906#M274783</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-05-26T08:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361913#M274784</link>
      <description>&lt;TABLE width="279"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="95"&gt;
&lt;P&gt;Quintile of Na&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="92"&gt;Quintile of K&lt;/TD&gt;
&lt;TD width="92"&gt;NaKgroup&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;13&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;14&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;23&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;24&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data looks as the table above.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 2 variables which are quintiles of Na and K (so each of them has 5 levels: 1st, 2nd,...5th quintile).&lt;/P&gt;
&lt;P&gt;Now I want to create new var as NaKgroup which combines those 2 quintiles variables. This new variable will have 25 categories.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 10:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361913#M274784</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2017-05-26T10:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361916#M274785</link>
      <description>&lt;P&gt;Again: &amp;nbsp;&lt;STRONG&gt;Please post test data in the form of a datastep.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;As such I now need to ask the question, are those variables nunmeric? &amp;nbsp;Also, why do the first two columns only appear in the first five rows?&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  nakgroup=input(cats(put(quit_na,best.),put(quint_k)),best.);
run;&lt;/PRE&gt;
&lt;P&gt;Assuming both columns are numeric and you want numeric result.&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 10:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361916#M274785</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-26T10:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361919#M274786</link>
      <description>&lt;P&gt;Thank you very much, RW9, for your reply.&lt;/P&gt;
&lt;P&gt;2 variables quintiles of Na and K are ordinal variables. They were created from Proc rank with the continuous variables of Na, K.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry I don't have SAS on the current PC so I can't post test data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just looked for hints.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I'll try your suggested solution with input statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 10:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361919#M274786</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2017-05-26T10:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361933#M274787</link>
      <description>&lt;P&gt;Cartesian Product.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select cats(na,k) as new&lt;/P&gt;
&lt;P&gt;&amp;nbsp;from&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(select distinct na from have),&lt;/P&gt;
&lt;P&gt;(select distinct k from have)&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 12:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/361933#M274787</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-26T12:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/362236#M274788</link>
      <description>&lt;P&gt;You can try below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select cat(t1.NA,t2.K) as NAK&lt;BR /&gt;from temp t1,&lt;BR /&gt;temp t2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 27 May 2017 20:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/362236#M274788</guid>
      <dc:creator>avishek2411</dc:creator>
      <dc:date>2017-05-27T20:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/362363#M274789</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52943"&gt;@Minhtrang&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much, RW9, for your reply.&lt;/P&gt;
&lt;P&gt;2 variables quintiles of Na and K are ordinal variables.&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt; They were created from Proc rank with the continuous variables of Na, K.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This suggests to me you already have a data set created by 2 proc ranks, say variables&amp;nbsp;Narank and Krank for each observation in the data set.&amp;nbsp; If so, I suspect you want something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; composite_rank=catx('_',narank,krank);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will create a character variable &lt;STRONG&gt;composite_rank&lt;/STRONG&gt; as "1_1", "1_2", ...&amp;nbsp; "5_4", "5_5".&amp;nbsp; The CATX function&amp;nbsp;works without objection enve when&amp;nbsp;narank and krank&amp;nbsp;are numerics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a numeric composite variable, then something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp; composite_rank=10*narank+krank;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just remember though: the numeric version assumes that krank is never more than 1 digit.&amp;nbsp; If krank reachs 2 digits (say deciles 1 to 10),&amp;nbsp;you have to multiple narank by 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A final note: the default of proc rank is to make qunitles 0 to 4 rather than 1 to 5.&amp;nbsp; In that case, the number version of the composite will show only 1 digit when narank=0 - a good reason to make a character composite.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 21:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/362363#M274789</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-28T21:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a composite categorical variable from other ordinal variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/362401#M274790</link>
      <description>&lt;P&gt;Dear mkeintz,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You understood my problem so well.&lt;/P&gt;
&lt;P&gt;Categorical variable is my desired outcome.&lt;/P&gt;
&lt;P&gt;Thank you so much for your explanation in depth as well as the given optimal solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Trang&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 01:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-composite-categorical-variable-from-other/m-p/362401#M274790</guid>
      <dc:creator>Minhtrang</dc:creator>
      <dc:date>2017-05-29T01:44:47Z</dc:date>
    </item>
  </channel>
</rss>

