<?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 1 categorical variable from a series of binary variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510041#M137210</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not use the WHICHN function?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
ED_Summary=whichn(1,of ED_type:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Nov 2018 19:46:31 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2018-11-02T19:46:31Z</dc:date>
    <item>
      <title>How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510035#M137207</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that looks something like this:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input studyID ED_type1 ED_type2 ED_type3;
cards;
1 . 1 1
2 . . 1 
3 1 . .
4 1 . 1
5 . 1 1
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I am trying to do is develop a summary variable for each record based on the ED_type variables. Essentially the ed_types are hierarchical (ED_type 1 being the top of the hierarchy, ED_type2 below it, and ED_type3 below that).&amp;nbsp; The summary variable needs to reflect whichever the "highest" ED type visit is for a given record.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clear as mud right? It might be easier with an example, in the end I want my new dataset to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
input studyID ED_type1 ED_type2 ED_type3 ED_Summary;
cards;
1 . 1 1 2
2 . . 1 3
3 1 . . 1
4 1 . 1 1
5 . 1 1 2
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since ID 1 has (1) in both ed visits in categories 2 and 3 it get's summarized as a 2 (because 2 falls above 3 on the hierarchy)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly, since ID 4 has visits in categories 1 and 3, then it get's a 1 because 1 is higher in the hierarchy than 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much in advance folks, you are always a huge help and any thoughts would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rightcoast&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510035#M137207</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2018-11-02T19:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510039#M137209</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2; 
input studyID ED_type1 ED_type2 ED_type3; 
if ed_type1=1 then ED_Summary=1; 
else if ed_type2=1 then ED_Summary=2; 
else if ed_type3=1 then ED_Summary=3; 
cards;
 ... 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510039#M137209</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T19:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510041#M137210</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not use the WHICHN function?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
ED_Summary=whichn(1,of ED_type:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510041#M137210</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-02T19:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510078#M137232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not use the WHICHN function?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
ED_Summary=whichn(1,of ED_type:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just need to be real sure that the sort order of the variable names is the actual hierarchy. Which this example is but you never know when going with actual data that the names might be actually needed in &amp;nbsp;Ed_typeAr Ed_typeBc Ed_typeA order.&lt;/P&gt;
&lt;P&gt;In which case list the hierarchy from left to right in the WHICHN instead of using the "of list:" construct.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510078#M137232</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-02T21:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510090#M137239</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I was aware of the subtleties regarding variable order. But for less experienced readers of this thread it's good that you pointed this out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;ED_type:&lt;/FONT&gt; shortcut abbreviates the list of variables in the PDV (program data vector) whose names start with "ED_type" -- in&amp;nbsp;&lt;EM&gt;the order in which they are stored in the PDV&lt;/EM&gt;, not in the alphabetical order of their names. In dataset HAVE (as created in the initial post) the three variables in question were created as a result of the INPUT statement, hence in the appropriate order for the WHICHN function to produce&amp;nbsp;the desired&amp;nbsp;results.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 22:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510090#M137239</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-02T22:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510097#M137244</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, I was aware of the subtleties regarding variable order. But for less experienced readers of this thread it's good that you pointed this out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;ED_type:&lt;/FONT&gt; shortcut abbreviates the list of variables in the PDV (program data vector) whose names start with "ED_type" -- in&amp;nbsp;&lt;EM&gt;the order in which they are stored in the PDV&lt;/EM&gt;, not in the alphabetical order of their names. In dataset HAVE (as created in the initial post) the three variables in question were created as a result of the INPUT statement, hence in the appropriate order for the WHICHN function to produce&amp;nbsp;the desired&amp;nbsp;results.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Right. I so seldom let anything else name my variables and I would create them in a numeric suffixed list I forget about the creation order.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 22:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510097#M137244</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-02T22:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510100#M137246</link>
      <description>&lt;P&gt;HI All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for your thoughts on this. It's much appreciated. I'd never heard of the WHICHN function, but I think it will be really useful going forward.&amp;nbsp; Unfortunately, the dataset I am using was created by someone else, so I'm not sure how things are ordered in the PDV. They are all ordered sequentially though (ED_1, ED_2 etc.) I'll give both the options a try and report back.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stay tuned!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rightcoast.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 23:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510100#M137246</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2018-11-02T23:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create 1 categorical variable from a series of binary variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510104#M137249</link>
      <description>&lt;P&gt;Thanks so much for your help everyone.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This solution took a bit more coding than the "whichn" method, but ultimately it was the only one I could make work. I think a lot of it had to do with the fact that I'm not entirely sure how the data was created so I couldn't get the syntax to fit. That being said, I learned about a new tool to use today, and I look forward to playing with it a bit and figuring it out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the meantime, thanks so much Paige! That code worked perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As always, all your help is much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rightcoast&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 00:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-1-categorical-variable-from-a-series-of-binary/m-p/510104#M137249</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2018-11-03T00:33:03Z</dc:date>
    </item>
  </channel>
</rss>

