<?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 Create new variable based on conditions across multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569952#M160673</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a new variable "type" based on conditions being true across multiple variables, but I have too many variables (~100) to type. I am using SAS Studio v 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is set up similar to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; INPUT id &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a_var_a a_var_b a_var_c a_var_d a_var_e
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b_var_a b_var_b b_var_c b_var_d
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c_var_a c_var_b c_var_c d_var_d;&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DATALINES;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01 1 0 0 0 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 0 1 0 0 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 03 0 0 1 0 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 04 0 0 0 1 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05 0 0 0 0 1 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 06 0 0 0 0 0 1 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07 0 0 0 0 0 0 1 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08 0 0 0 0 0 0 0 1 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09 0 0 0 0 0 0 0 0 1 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10 0 0 0 0 0 0 0 0 0 1 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11 0 0 0 0 0 0 0 0 0 0 1 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12 0 0 0 0 0 0 0 0 0 0 0 1 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13 0 0 0 0 0 0 0 0 0 0 0 0 1 &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I thought it would be as simple as:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  Set have;
   &lt;BR /&gt;  If a_var: = 1 then type = 1;
  Else If b_var: = 1 then type = 2;
  Else If c_var: = 1 then type = 3;
  Else type = 0;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However I keep getting an error code because I am not allowed to group the variables.&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I tried doing the same thing with an array but I am still unable to arrive at a solution:&lt;/DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  Set have;

  Array a (*) a_var:;
  Array other (2,4) b_var: c_var:;
&lt;BR /&gt;  do i = 1 to dim(a);
  If a(i) = 1 then type=1;
  end;

  do i = 1 to 4;
  If other (1,i) = 1 then type=2;
  If other (2,i) = 1 then type=3;
  Else type=0;
  end;

  drop i;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2019 19:16:23 GMT</pubDate>
    <dc:creator>Doyinsola</dc:creator>
    <dc:date>2019-06-28T19:16:23Z</dc:date>
    <item>
      <title>Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569952#M160673</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a new variable "type" based on conditions being true across multiple variables, but I have too many variables (~100) to type. I am using SAS Studio v 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is set up similar to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; INPUT id &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a_var_a a_var_b a_var_c a_var_d a_var_e
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b_var_a b_var_b b_var_c b_var_d
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c_var_a c_var_b c_var_c d_var_d;&lt;BR /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DATALINES;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01 1 0 0 0 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02 0 1 0 0 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 03 0 0 1 0 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 04 0 0 0 1 0 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05 0 0 0 0 1 0 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 06 0 0 0 0 0 1 0 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07 0 0 0 0 0 0 1 0 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08 0 0 0 0 0 0 0 1 0 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09 0 0 0 0 0 0 0 0 1 0 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10 0 0 0 0 0 0 0 0 0 1 0 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11 0 0 0 0 0 0 0 0 0 0 1 0 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12 0 0 0 0 0 0 0 0 0 0 0 1 0
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13 0 0 0 0 0 0 0 0 0 0 0 0 1 &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I thought it would be as simple as:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  Set have;
   &lt;BR /&gt;  If a_var: = 1 then type = 1;
  Else If b_var: = 1 then type = 2;
  Else If c_var: = 1 then type = 3;
  Else type = 0;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However I keep getting an error code because I am not allowed to group the variables.&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I tried doing the same thing with an array but I am still unable to arrive at a solution:&lt;/DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  Set have;

  Array a (*) a_var:;
  Array other (2,4) b_var: c_var:;
&lt;BR /&gt;  do i = 1 to dim(a);
  If a(i) = 1 then type=1;
  end;

  do i = 1 to 4;
  If other (1,i) = 1 then type=2;
  If other (2,i) = 1 then type=3;
  Else type=0;
  end;

  drop i;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 19:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569952#M160673</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2019-06-28T19:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569959#M160676</link>
      <description>&lt;P&gt;Your example data implies that each of your rows may only have one value of '1' and you want the position in the list of variables returned as the value of TYPE.&lt;/P&gt;
&lt;P&gt;If that is the case the perhaps the WHICHN function will solve the problem:&lt;/P&gt;
&lt;PRE&gt;DATA have;
INPUT id  
a_var_a a_var_b a_var_c a_var_d a_var_e
b_var_a b_var_b b_var_c b_var_d
c_var_a c_var_b c_var_c d_var_d;

array  values       a_var_a a_var_b a_var_c a_var_d a_var_e
b_var_a b_var_b b_var_c b_var_d
c_var_a c_var_b c_var_c d_var_d;
type = whichn(1,of values(*));

DATALINES;
01 1 0 0 0 0 0 0 0 0 0 0 0 0
02 0 1 0 0 0 0 0 0 0 0 0 0 0
03 0 0 1 0 0 0 0 0 0 0 0 0 0
04 0 0 0 1 0 0 0 0 0 0 0 0 0
05 0 0 0 0 1 0 0 0 0 0 0 0 0
06 0 0 0 0 0 1 0 0 0 0 0 0 0
07 0 0 0 0 0 0 1 0 0 0 0 0 0
08 0 0 0 0 0 0 0 1 0 0 0 0 0
09 0 0 0 0 0 0 0 0 1 0 0 0 0
10 0 0 0 0 0 0 0 0 0 1 0 0 0
11 0 0 0 0 0 0 0 0 0 0 1 0 0
12 0 0 0 0 0 0 0 0 0 0 0 1 0
13 0 0 0 0 0 0 0 0 0 0 0 0 1  
;
Run;&lt;/PRE&gt;
&lt;P&gt;Whichn looks for the value of the first parameter, in this case 1, and returns the position number of the value found in the list of variables or 0 if not found. The " of arrayname(*)" provides a list of variables and the function would return the list position in regards to the order they are listed in the array definition statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to consider multiple variables with values then you need to provide a clearer example of that data and the rules for assigning the type based on two or more values.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 19:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569959#M160676</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-28T19:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569961#M160677</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/120813"&gt;@Doyinsola&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a new variable "type" based on conditions being true across multiple variables, but I have too many variables (~100) to type. I am using SAS Studio v 9.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data is set up similar to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;D&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;proc sgplot data=sashelp.class;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;series x=height y=weight;&lt;BR /&gt;xaxis labelattrs=(family='Arial');&lt;BR /&gt;run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I thought it would be as simple as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  Set have;
   &lt;BR /&gt;  If a_var: = 1 then type = 1;
  Else If b_var: = 1 then type = 2;
  Else If c_var: = 1 then type = 3;
  Else type = 0;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However I keep getting an error code because I am not allowed to group the variables.&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try the &lt;A href="http://documentation.sas.com/?cdcId=pgmmvacdc&amp;amp;cdcVersion=9.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0zs0pv38mel2jn1in4lte2akx4d.htm&amp;amp;locale=en" target="_self"&gt;WHICHN function&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
        INPUT id  
        a_var_a a_var_b a_var_c a_var_d a_var_e
        b_var_a b_var_b b_var_c b_var_d
        c_var_a c_var_b c_var_c d_var_d;
		if whichn(1,of a_var:)&amp;gt;0 then type = 1;
        DATALINES;
              01 1 0 0 0 0 0 0 0 0 0 0 0 0
              02 0 1 0 0 0 0 0 0 0 0 0 0 0
              03 0 0 1 0 0 0 0 0 0 0 0 0 0
              04 0 0 0 1 0 0 0 0 0 0 0 0 0
              05 0 0 0 0 1 0 0 0 0 0 0 0 0
              06 0 0 0 0 0 1 0 0 0 0 0 0 0
              07 0 0 0 0 0 0 1 0 0 0 0 0 0
              08 0 0 0 0 0 0 0 1 0 0 0 0 0
              09 0 0 0 0 0 0 0 0 1 0 0 0 0
              10 0 0 0 0 0 0 0 0 0 1 0 0 0
              11 0 0 0 0 0 0 0 0 0 0 1 0 0
              12 0 0 0 0 0 0 0 0 0 0 0 1 0
              13 0 0 0 0 0 0 0 0 0 0 0 0 1  
              ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By the way, if you have hundreds of variables, might it not make more sense to name them a1-a100, &lt;EM&gt;etc&lt;/EM&gt;.?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 19:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569961#M160677</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-28T19:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569975#M160682</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This won't work because I am trying to create 3 categories of the "type" variable (0,1,2, and 3) based on how the conditions are met.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 20:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569975#M160682</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2019-06-28T20:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569977#M160683</link>
      <description>&lt;P&gt;Thanks, but I am less concerned with the position of the 1. Instead,&amp;nbsp;I am trying to create 3 categories of the "type" variable (0,1,2, and 3) based on how the conditions are met.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 20:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569977#M160683</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2019-06-28T20:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569983#M160688</link>
      <description>So what's the logic?</description>
      <pubDate>Fri, 28 Jun 2019 20:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569983#M160688</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-28T20:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569985#M160689</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/120813"&gt;@Doyinsola&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, but I am less concerned with the position of the 1. Instead,&amp;nbsp;I am trying to create 3 categories of the "type" variable (0,1,2, and 3) based on how the conditions are met.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you need to explicitly give us the rules for creating the type variable.&lt;/P&gt;
&lt;P&gt;Code that does not do what you want does not provide details on how to do what is needed.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 20:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569985#M160689</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-28T20:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569991#M160694</link>
      <description>"type" is:&lt;BR /&gt;1 If any of the group a vars (a_var:) are equal to 1&lt;BR /&gt;2 If any of the group b vars (b_var:) are equal to 1&lt;BR /&gt;3 If any of the group c vars (c_var:) are equal to 1&lt;BR /&gt;else 0</description>
      <pubDate>Fri, 28 Jun 2019 21:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569991#M160694</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2019-06-28T21:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569995#M160698</link>
      <description>Sure!&lt;BR /&gt;&lt;BR /&gt;"type" is coded as:&lt;BR /&gt;1 If any of the group a vars (a_var:) are equal to 1&lt;BR /&gt;2 If any of the group b vars (b_var:) are equal to 1&lt;BR /&gt;3 If any of the group c vars (c_var:) are equal to 1&lt;BR /&gt;else 0</description>
      <pubDate>Fri, 28 Jun 2019 21:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569995#M160698</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2019-06-28T21:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569997#M160700</link>
      <description>if whichn(1, of a_var:)&amp;gt;1 then code=1;&lt;BR /&gt;else if whichn(1, of b_var:)&amp;gt;1 then code=2;&lt;BR /&gt;......</description>
      <pubDate>Fri, 28 Jun 2019 21:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/569997#M160700</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-28T21:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570003#M160702</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/120813"&gt;@Doyinsola&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;"type" is:&lt;BR /&gt;1 If any of the group a vars (a_var:) are equal to 1&lt;BR /&gt;2 If any of the group b vars (b_var:) are equal to 1&lt;BR /&gt;3 If any of the group c vars (c_var:) are equal to 1&lt;BR /&gt;else 0&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like writing some slightly obscure code:&lt;/P&gt;
&lt;PRE&gt;code = (whichn(1, of a_var:)&amp;gt;0 )*1 +  (whichn(1, of b_var:)&amp;gt;0 )*2 +
       (whichn(1, of c_var:)&amp;gt;0 )*3 ;&lt;/PRE&gt;
&lt;P&gt;which assumes that you have 1's in only one of the a_ b_ or c_ var groups. If this results in a 4 or 5 then your problem description is still incomplete.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 21:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570003#M160702</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-28T21:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570005#M160703</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/120813"&gt;@Doyinsola&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This won't work because I am trying to create 3 categories of the "type" variable (0,1,2, and 3) based on how the conditions are met.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's right, I said "something like this". It covers the case where any of the "a" variables equals 1. Obvious modifications to the code get what you want, that I suspect you can make without further issue.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 21:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570005#M160703</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-28T21:43:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570006#M160704</link>
      <description>Thank you, it almost worked! (using the code below) but some values end up as missing. There should be no missing values, given each row will satisfy at least one of the conditions.&lt;BR /&gt;&lt;BR /&gt;DATA have;&lt;BR /&gt;INPUT id&lt;BR /&gt;a_var_a a_var_b a_var_c a_var_d a_var_e&lt;BR /&gt;b_var_a b_var_b b_var_c b_var_d&lt;BR /&gt;c_var_a c_var_b c_var_c d_var_d;&lt;BR /&gt;if whichn(1, of a_var:) &amp;gt;1 then type=1;&lt;BR /&gt;else if whichn(1, of b_var:) &amp;gt;1 then type=2;&lt;BR /&gt;else if whichn(1, of c_var:) &amp;gt;1 then type=3;&lt;BR /&gt;else type = 0;&lt;BR /&gt;DATALINES;&lt;BR /&gt;01 1 0 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;02 0 1 0 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;03 0 0 1 0 0 0 0 0 0 0 0 0 0&lt;BR /&gt;04 0 0 0 1 0 0 0 0 0 0 0 0 0&lt;BR /&gt;05 0 0 0 0 1 0 0 0 0 0 0 0 0&lt;BR /&gt;06 0 0 0 0 0 1 0 0 0 0 0 0 0&lt;BR /&gt;07 0 0 0 0 0 0 1 0 0 0 0 0 0&lt;BR /&gt;08 0 0 0 0 0 0 0 1 0 0 0 0 0&lt;BR /&gt;09 0 0 0 0 0 0 0 0 1 0 0 0 0&lt;BR /&gt;10 0 0 0 0 0 0 0 0 0 1 0 0 0&lt;BR /&gt;11 0 0 0 0 0 0 0 0 0 0 1 0 0&lt;BR /&gt;12 0 0 0 0 0 0 0 0 0 0 0 1 0&lt;BR /&gt;13 0 0 0 0 0 0 0 0 0 0 0 0 1&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Proc Print Data = have; run;</description>
      <pubDate>Fri, 28 Jun 2019 21:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570006#M160704</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2019-06-28T21:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable based on conditions across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570009#M160705</link>
      <description>&lt;P&gt;Thank you!&lt;BR /&gt;&lt;BR /&gt;Some slight modifications but this is the code that eventually worked.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
INPUT id
a_var_a a_var_b a_var_c a_var_d a_var_e
b_var_a b_var_b b_var_c b_var_d
c_var_a c_var_b c_var_c c_var_d;
if whichn (1, of a_var:) =&amp;gt;1 then type=1;
else if whichn (1, of b_var:) =&amp;gt;1 then type=2;
else if whichn(1, of c_var:) =&amp;gt;1 then type=3;
else type = 0;
DATALINES;
01 1 0 0 0 0 0 0 0 0 0 0 0 0
02 0 1 0 0 0 0 0 0 0 0 0 0 0
03 0 0 1 0 0 0 0 0 0 0 0 0 0
04 0 0 0 1 0 0 0 0 0 0 0 0 0
05 0 0 0 0 1 0 0 0 0 0 0 0 0
06 0 0 0 0 0 1 0 0 0 0 0 0 0
07 0 0 0 0 0 0 1 0 0 0 0 0 0
08 0 0 0 0 0 0 0 1 0 0 0 0 0
09 0 0 0 0 0 0 0 0 1 0 0 0 0
10 0 0 0 0 0 0 0 0 0 1 0 0 0
11 0 0 0 0 0 0 0 0 0 0 1 0 0
12 0 0 0 0 0 0 0 0 0 0 0 1 0
13 0 0 0 0 0 0 0 0 0 0 0 0 1
14 0 0 0 0 0 0 0 0 0 0 0 0 0
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2019 22:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-based-on-conditions-across-multiple/m-p/570009#M160705</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2019-06-28T22:00:13Z</dc:date>
    </item>
  </channel>
</rss>

