<?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 If...then... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then/m-p/570435#M160848</link>
    <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it's probably an easy code to write but&amp;nbsp; i want to be corrected on this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a variable heartvar6 , such that heartvar6=1 if a participant has 1 or more heart failures (eg any of heartvar1-heartvar5 = 1). I also want to call heartvar6 as missing if the patient has a combination of 0's and missings . And then 0 otherwise.&lt;/P&gt;&lt;P&gt;For example, in the dataset i posted, i want observation 3 to be missing but observation 5 will be 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input heart1 heart2 heart3 heart4 heart5;
datalines;
1 0 0 0 0
0 1 . .0
0 0 0 . 0
1 1 0 1 0
0 0 0 0 0
; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data two; set one;&lt;BR /&gt;if heartvar1 =1 or heartvar2=1 or heartvar3=1 or heartvar4=1 or heartvar5=1 then heartvar6=1;&lt;BR /&gt;else if heartvar1=0 and heartvar2=0 and heartvar3=0 and heartvar4=0 and heartvar5=0 then heartvar6=0;&lt;BR /&gt;else heartvar6=.;&lt;BR /&gt;proc print; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please can i use an array for this?&lt;/P&gt;&lt;P&gt;This code gave me the logic that i wanted to implement. is there a more efficient way of writing this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jul 2019 05:56:11 GMT</pubDate>
    <dc:creator>ChuksManuel</dc:creator>
    <dc:date>2019-07-02T05:56:11Z</dc:date>
    <item>
      <title>If...then...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then/m-p/570435#M160848</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it's probably an easy code to write but&amp;nbsp; i want to be corrected on this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a variable heartvar6 , such that heartvar6=1 if a participant has 1 or more heart failures (eg any of heartvar1-heartvar5 = 1). I also want to call heartvar6 as missing if the patient has a combination of 0's and missings . And then 0 otherwise.&lt;/P&gt;&lt;P&gt;For example, in the dataset i posted, i want observation 3 to be missing but observation 5 will be 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input heart1 heart2 heart3 heart4 heart5;
datalines;
1 0 0 0 0
0 1 . .0
0 0 0 . 0
1 1 0 1 0
0 0 0 0 0
; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data two; set one;&lt;BR /&gt;if heartvar1 =1 or heartvar2=1 or heartvar3=1 or heartvar4=1 or heartvar5=1 then heartvar6=1;&lt;BR /&gt;else if heartvar1=0 and heartvar2=0 and heartvar3=0 and heartvar4=0 and heartvar5=0 then heartvar6=0;&lt;BR /&gt;else heartvar6=.;&lt;BR /&gt;proc print; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please can i use an array for this?&lt;/P&gt;&lt;P&gt;This code gave me the logic that i wanted to implement. is there a more efficient way of writing this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 05:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then/m-p/570435#M160848</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2019-07-02T05:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: If...then...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then/m-p/570445#M160849</link>
      <description>&lt;P&gt;Use of Array simplifies the program but must know that the use of double ^ before an expression gets either 1 or 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data one;
input heart1 heart2 heart3 heart4 heart5;
datalines;
1 0 0 0 0
0 1 . . 0
0 0 0 . 0
1 1 0 1 0
0 0 0 0 0
; 
run;


data two;
   set one;
   array h heart1 - heart5;
   heart6 = ^^whichN(1, of h[*]);
   if heart6 = 0 and nmiss(of h[*]) then heart6 = .;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 06:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then/m-p/570445#M160849</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-07-02T06:45:11Z</dc:date>
    </item>
  </channel>
</rss>

