<?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: process 'if statement' more efficiently. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136329#M27623</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DBailey suggested:&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;how about&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;if s1 * s2 * s3 * s4 * s5 = 0 then sex='M';&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;else sex='F';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, but this doesn't work. The product of a missing value with anything is missing:&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;input S1-S5 var2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0 . . . . 11&lt;/P&gt;&lt;P&gt;. 0 . . . 22&lt;/P&gt;&lt;P&gt;. . 0 . . 33&lt;/P&gt;&lt;P&gt;1 . . . . 44&lt;/P&gt;&lt;P&gt;. . . . 0 55&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;set one;&lt;/P&gt;&lt;P&gt;if s1 * s2 * s3 * s4 * s5 = 0 then sex='M';&lt;/P&gt;&lt;P&gt;else sex='F';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print data= two;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="512"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl25" height="18" width="64"&gt;Obs&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S1&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S2&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S3&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S4&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S5&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;var2&lt;/TD&gt;&lt;TD class="xl27" width="64"&gt;sex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;1&lt;/TD&gt;&lt;TD class="xl24"&gt;0&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;11&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;2&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;0&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;22&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;3&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;0&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;33&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;4&lt;/TD&gt;&lt;TD class="xl24"&gt;1&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;44&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl30" height="17"&gt;5&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;0&lt;/TD&gt;&lt;TD class="xl31"&gt;55&lt;/TD&gt;&lt;TD class="xl32"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Oct 2014 23:27:35 GMT</pubDate>
    <dc:creator>dkb</dc:creator>
    <dc:date>2014-10-21T23:27:35Z</dc:date>
    <item>
      <title>process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136323#M27617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a small data set like this on the bottom.&lt;/P&gt;&lt;P&gt;The logic is: if any of the variable (S1-S5) contains 0, the sex is defined as 'M', otherwise as 'F'.&lt;/P&gt;&lt;P&gt;My question is: is there any way we can replace the repeated if statements with a more efficient coding style?&lt;/P&gt;&lt;P&gt;It will be very helpful when the variable goes from S1 to S200 something.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*;&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;input S1-S5 var2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0 . . . . 11&lt;/P&gt;&lt;P&gt;. 0 . . . 22&lt;/P&gt;&lt;P&gt;. . 0 . . 33&lt;/P&gt;&lt;P&gt;1 . . . . 44&lt;/P&gt;&lt;P&gt;. . . . 0 55&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;set one;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if S1=0 then sex='M';&lt;/P&gt;&lt;P&gt;else if S2=0 then sex='M';&lt;/P&gt;&lt;P&gt;else if S3=0 then sex='M';&lt;/P&gt;&lt;P&gt;else if S4=0 then sex='M';&lt;/P&gt;&lt;P&gt;else if S5=0 then sex='M';&lt;/P&gt;&lt;P&gt;else&amp;nbsp; sex='F';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;*;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 21:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136323#M27617</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2014-10-21T21:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136324#M27618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you only have 5 I wouldn't even bother with an array statement. By default the max/min/sum functions ignore missing values so something like the following can work.&lt;/P&gt;&lt;P&gt;I've included for the case where all may be missing with an else clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;set one;&lt;/P&gt;&lt;P&gt;if max(s1,s2,s3,s4,s5)=0 then sex='M';&lt;/P&gt;&lt;P&gt;else if max(s1,s2,s3,s4,s5)=1 then sex='F';&lt;/P&gt;&lt;P&gt;else sex='U';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 21:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136324#M27618</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-21T21:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136325#M27619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data one;&lt;BR /&gt;input S1-S5 var2;&lt;BR /&gt;datalines;&lt;BR /&gt;0 . . . . 11&lt;BR /&gt;. 0 . . . 22&lt;BR /&gt;. . 0 . . 33&lt;BR /&gt;1 . . . . 44&lt;BR /&gt;. . . . 0 55&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(drop=i);&lt;BR /&gt;set one;&lt;BR /&gt;sex = 'F';&lt;BR /&gt;array s(*) s1-s5;&lt;BR /&gt;do i=1 to dim(s);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if s(i) = 0 then sex='M';&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 21:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136325#M27619</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-21T21:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136326#M27620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;how about&lt;/P&gt;&lt;P&gt;if s1 * s2 * s3 * s4 * s5 = 0 then set='M';&lt;/P&gt;&lt;P&gt;else sex='F';&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 21:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136326#M27620</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2014-10-21T21:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136327#M27621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This will generate missing values but on the same lines we can do something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set one;&lt;/P&gt;&lt;P&gt;if sum(of s:) = 0 then sex='M';&lt;/P&gt;&lt;P&gt;else sex='F';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 22:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136327#M27621</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-21T22:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136328#M27622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, ALL,&lt;/P&gt;&lt;P&gt;Thanks for you quick help on this topic.&lt;/P&gt;&lt;P&gt;I personally think the array one works the best for my situation and beyond (e.g. when you have character variables instead of numeric ones in this case). All other responses helped to solve my problem. Thank you all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 22:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136328#M27622</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2014-10-21T22:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136329#M27623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DBailey suggested:&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;how about&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;if s1 * s2 * s3 * s4 * s5 = 0 then sex='M';&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="font-style: inherit; font-family: inherit;"&gt;&lt;STRONG&gt;else sex='F';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, but this doesn't work. The product of a missing value with anything is missing:&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;input S1-S5 var2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0 . . . . 11&lt;/P&gt;&lt;P&gt;. 0 . . . 22&lt;/P&gt;&lt;P&gt;. . 0 . . 33&lt;/P&gt;&lt;P&gt;1 . . . . 44&lt;/P&gt;&lt;P&gt;. . . . 0 55&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;set one;&lt;/P&gt;&lt;P&gt;if s1 * s2 * s3 * s4 * s5 = 0 then sex='M';&lt;/P&gt;&lt;P&gt;else sex='F';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print data= two;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="512"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl25" height="18" width="64"&gt;Obs&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S1&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S2&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S3&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S4&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;S5&lt;/TD&gt;&lt;TD class="xl26" width="64"&gt;var2&lt;/TD&gt;&lt;TD class="xl27" width="64"&gt;sex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;1&lt;/TD&gt;&lt;TD class="xl24"&gt;0&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;11&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;2&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;0&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;22&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;3&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;0&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;33&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl28" height="18"&gt;4&lt;/TD&gt;&lt;TD class="xl24"&gt;1&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;.&lt;/TD&gt;&lt;TD class="xl24"&gt;44&lt;/TD&gt;&lt;TD class="xl29"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl30" height="17"&gt;5&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;.&lt;/TD&gt;&lt;TD class="xl31"&gt;0&lt;/TD&gt;&lt;TD class="xl31"&gt;55&lt;/TD&gt;&lt;TD class="xl32"&gt;F&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 23:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136329#M27623</guid>
      <dc:creator>dkb</dc:creator>
      <dc:date>2014-10-21T23:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136330#M27624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you think arrays would be your best choice then I'd suggest using something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set one;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array s(*) $ s1-s5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if '0' in s then sex='M';&lt;/P&gt;&lt;P&gt;&amp;nbsp; else sex='F';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 23:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136330#M27624</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-10-21T23:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: process 'if statement' more efficiently.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136331#M27625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for Arthur's additional comments.&lt;/P&gt;&lt;P&gt;I really learned something from you guys.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Oct 2014 02:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/process-if-statement-more-efficiently/m-p/136331#M27625</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2014-10-22T02:38:51Z</dc:date>
    </item>
  </channel>
</rss>

