<?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 variable based on multiple conditions with lots of variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973584#M377723</link>
    <description>&lt;P&gt;Does not look like you need to use looping.&amp;nbsp; Instead just use functions that can operate on multiple variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input q1-q20 flag_want;
datalines;
20  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20 20  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20  0 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
 0  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 -8  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-8 -7 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-7  1  1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
;

data want;
  set have;
  if max(0,of q1-q20) &amp;gt; 0 then flag=1;
  else if whichn(-7,of q1-q20)
       or whichn(-8,of q1-q20)
       or whichn(-9,of q1-q20)
       then flag=.;
  else if 0=min(0,of q1-q20)=max(0,of q1-q20) then flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And perhaps if those special values, -7, -8 and -9 are the only valid values that are less then zero then the second IF can be simpler.&amp;nbsp; For example you could use MIN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  else min(0,of q1-q20)&amp;lt;0 then flag=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if -7, -8 and -9 are really just different special missing codes if you actually code the data using special missing values (instead of valid numbers) you could use the NMISS() function.&amp;nbsp; For example by using .A, .B, and .C instead of -7, -8 and -9.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;missing abc ;
data have;
  input q1-q20 flag_want;
datalines;
20  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20 20  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20  0  A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
 0  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0  B  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
 B  A  A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
 A  1  1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
;

data want;
  set have;
  if max(0,of q1-q20) &amp;gt; 0 then flag=1;
  else if 0&amp;lt;nmiss(of q1-q20) then flag=.;
  else if 0=min(0,of q1-q20)=max(0,of q1-q20) then flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Aug 2025 02:09:54 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-08-29T02:09:54Z</dc:date>
    <item>
      <title>How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973568#M377712</link>
      <description>&lt;P&gt;Hi, I have a lots of variables, q1 to q20 let's say.&amp;nbsp; And I want to create a new variable by several conditions based on the 20 variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. if any one of the 20 variables &amp;gt; 0 then flag=1; (as long as anyone of them &amp;gt; 0)&lt;/P&gt;
&lt;P&gt;2.else if any one of the 20 variables = -7 or -8 or -9 then flag=.; (for the rest of the values which &amp;lt;=0)&lt;/P&gt;
&lt;P&gt;3. else if ALL of the 20 variables = 0 then flag=0; (for the rest of the values which =0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;q1  q2  q3 .........   q20     flag
20  0    0              0       1
20  20   0              0       1
20  0   -7              0       1
0   0    0              0       0
0  -8    0              0       .
-8 -7   -7              0       .
   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because there are too many variables, I tried array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flag=0;
array q q1-q20;
       do over q;
                    if q &amp;gt; 0 then flag=1;
                    else if q in ('7', '8', '9') then flag=.;
        end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the else if here didn't work. Does anyone know how to deal with many variables and multiple conditions? Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Aug 2025 20:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973568#M377712</guid>
      <dc:creator>SAS-questioner</dc:creator>
      <dc:date>2025-08-28T20:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973569#M377713</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array q q1-20;
    /* Condition 1 */
    if max(of q:)&amp;gt;0 then flag=1;
    /* Condition 2 */
    else do i=1 to 20;
       if q(i) in (-9 -8 -7) then flag=.;
       leave;
    end;
    /* Condition 3 */
    else if max(of q:)=0 and min(of q:)=0 then flag=0;
run;&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;I wonder if there is a flaw in your logic. If q1 = -1 and all the other q's are equal to zero, then none of the conditions execute. The code mirrors your logic. However, this gives a value of FLAG equal to missing, is that what you want?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Aug 2025 20:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973569#M377713</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-08-28T20:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973571#M377715</link>
      <description>Could you be more specific about the flaw? if q1= -7 or -8 or -9 and all the other q's are equal to 0, then flag should be missing. I tried your code, but error said "ERROR 160-185: No matching IF-THEN clause" for the last else there.</description>
      <pubDate>Thu, 28 Aug 2025 21:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973571#M377715</guid>
      <dc:creator>SAS-questioner</dc:creator>
      <dc:date>2025-08-28T21:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973573#M377717</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	q1=1; q2=0;	q3= 2; q4=3; q5=4; output;
	q1=0; q2=0;	q3= 0; q4=0; q5=0; output;
	q1=0; q2=0;	q3=-9; q4=0; q5=-7;	output;
run;&lt;BR /&gt;
/* This should work with your data set of 20 vars */
data want;
  set have;
  if (sum(of q:)=0) then flag=0;
  else if (max(of q:) &amp;gt; 0) then flag=1;
  else if (sum(whichn(-9, of q:),whichn(-8, of q:),whichn(-7, of q:)  ) &amp;gt; 0) then flag=-1;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Aug 2025 21:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973573#M377717</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2025-08-28T21:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973581#M377720</link>
      <description>&lt;P&gt;Below option should work even if the sum of all q vars should result in zero (obs 7 in sample data).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length flag_want 8;
  infile datalines truncover;
  input (q1-q20 flag_want) (:best32.);
  datalines;
20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20 0 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 -8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-8 -7 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-7 1 1 1 1 1 1 1  0 0 0 0 0 0 0 0 0 0 0 0 1
;
run;

data want;
  length flag_derived 8;
  set have;
  array a_q (*) q:;
  do i=1 to dim(a_q);
    /*  1. if any one of the 20 variables &amp;gt; 0 then flag=1 */
    if a_q[i]&amp;gt;0 then do; flag_derived=1; leave; end;
    /* 2.else if any one of the 20 variables = -7 or -8 or -9 then flag=. */
    else 
    if a_q[i] in (-7,-8,-9) then flag_derived=sum(flag_derived,2);
    /* 3. else if ALL of the 20 variables = 0 then flag=0 */
    else
    if a_q[i]=0 then flag_derived=sum(flag_derived,0);
  end;
  if flag_derived&amp;gt;1 then call missing(flag_derived);
  drop i;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1756431237444.png" style="width: 549px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109397iB93FCDB3C951CC54/image-dimensions/549x110?v=v2" width="549" height="110" role="button" title="Patrick_0-1756431237444.png" alt="Patrick_0-1756431237444.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 01:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973581#M377720</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2025-08-29T01:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973584#M377723</link>
      <description>&lt;P&gt;Does not look like you need to use looping.&amp;nbsp; Instead just use functions that can operate on multiple variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input q1-q20 flag_want;
datalines;
20  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20 20  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20  0 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
 0  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 -8  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-8 -7 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-7  1  1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
;

data want;
  set have;
  if max(0,of q1-q20) &amp;gt; 0 then flag=1;
  else if whichn(-7,of q1-q20)
       or whichn(-8,of q1-q20)
       or whichn(-9,of q1-q20)
       then flag=.;
  else if 0=min(0,of q1-q20)=max(0,of q1-q20) then flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And perhaps if those special values, -7, -8 and -9 are the only valid values that are less then zero then the second IF can be simpler.&amp;nbsp; For example you could use MIN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  else min(0,of q1-q20)&amp;lt;0 then flag=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if -7, -8 and -9 are really just different special missing codes if you actually code the data using special missing values (instead of valid numbers) you could use the NMISS() function.&amp;nbsp; For example by using .A, .B, and .C instead of -7, -8 and -9.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;missing abc ;
data have;
  input q1-q20 flag_want;
datalines;
20  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20 20  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20  0  A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
 0  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0  B  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
 B  A  A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
 A  1  1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
;

data want;
  set have;
  if max(0,of q1-q20) &amp;gt; 0 then flag=1;
  else if 0&amp;lt;nmiss(of q1-q20) then flag=.;
  else if 0=min(0,of q1-q20)=max(0,of q1-q20) then flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 02:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973584#M377723</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-08-29T02:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973585#M377724</link>
      <description>&lt;P&gt;If you really want to use looping try these loops.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  array q q1-q20;
  flag=0;
  do index=1 to dim(q) while(flag=0);
    if 0 &amp;lt; q[index] then flag=1;
  end;
  do index=1 to dim(q) while(flag=0);
    if q[index] in (-7 -8 -9) then flag=.;
    else if q[index] ne 0 then put 'WARNING: Unexpected value. ' q[index]=;
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 02:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973585#M377724</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-08-29T02:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973600#M377725</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input q1-q20 ;
datalines;
20  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20 20  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
20  0 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
 0  0  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 -8  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-8 -7 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .
-7  1  1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
;


data want;
  set have;
  array x{*} _numeric_ ;
if max(of x{*})&amp;gt;0 then flag=1;
 else if ((-7 in x) or (-8 in x) or (-9 in x)) and max(of x{*})&amp;lt;=0 then flag=.;
  else if max(of x{*})=0 and min(of x{*})=0 then flag=0;
run; 



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Aug 2025 06:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973600#M377725</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-08-29T06:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973623#M377728</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376504"&gt;@SAS-questioner&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Could you be more specific about the flaw? if q1= -7 or -8 or -9 and all the other q's are equal to 0, then flag should be missing. I tried your code, but error said "ERROR 160-185: No matching IF-THEN clause" for the last else there.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What happens if your logic encounters q1 = -1 (not negative seven) and the rest of the q values are zeros? It also is missing according to your stated logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you get an error in the log, show us the entire log for this data step. Do not show us a partial log, and do not show us just the error messages.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 10:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973623#M377728</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-08-29T10:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973634#M377729</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp; Neat. Not sure if I was ever aware of syntax like&amp;nbsp;(-7 in x). That's certainly useful.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 11:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973634#M377729</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2025-08-29T11:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973638#M377730</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376504"&gt;@SAS-questioner&lt;/a&gt;&amp;nbsp;, does this answer your question?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input q1 q2 q3 q4 q5 q6;
   datalines;
20  0    0   4   5   0
20  20   0  -1  -2   0
20  0   -7   1   2   0
0   0    0   0   0   0
0  -8    0   -1  -3  0
-8 -7   -7   -1  -1  0
1   2   3    0   -1  -20
-9  20  1   2   3    1
-7  -1  0   0   -8  -9
;
run;
proc print data=have;run;
data want (drop=i);
   set have;
   array q[*] q:;
   do i=1 to dim(q);
      if q[i]&amp;gt;0 then flag=1;
      else if q[i] in (-7,-8,-9)
         then flag=.;
      else if max(of q:)=0 and 
              min(of q:)=0
         then flag=0;
   end;
run;
proc print data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1756472650618.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109420i14C50D5F35CF5914/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1756472650618.png" alt="dxiao2017_0-1756472650618.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 13:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973638#M377730</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-08-29T13:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable based on multiple conditions with lots of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973646#M377731</link>
      <description>&lt;P&gt;And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376504"&gt;@SAS-questioner&lt;/a&gt;&amp;nbsp;, according to your if/else condition, if any row has all values&amp;lt;=0, the flag of that row is missing, regardless there is -7, -8, and -9 in that row or not. I think this is also the question&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;prompted. See the example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input q1 q2 q3 q4 q5 q6;
   datalines;
20  0    0   4   5   0
20  20   0  -1  -2   0
20  0   -7   1   2   0
0   0    0   0   0   0
0  -8    0   -1  -3  0
-8 -7   -7   -1  -1  0
1   2   3    0   -1  -20
-9  20  1   2   3    1
-7  -1  0   0   -8  -9
-1  -2  -3  -4  -5  -6
0   -1  -2  -3   0  -1
;
run;
proc print data=have;run;
data want (drop=i);
   set have;
   array q[*] q:;
   do i=1 to dim(q);
      if q[i]&amp;gt;0 then flag=1;
      else if q[i] in (-7,-8,-9)
         then flag=.;
      else if max(of q:)=0 and 
              min(of q:)=0
         then flag=0;
   end;
run;
proc print data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1756473912094.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109427i126989AC9830B225/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1756473912094.png" alt="dxiao2017_0-1756473912094.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Aug 2025 13:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-based-on-multiple-conditions-with-lots/m-p/973646#M377731</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-08-29T13:27:45Z</dc:date>
    </item>
  </channel>
</rss>

