<?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: IF-THEN-ELSE | Multiple Conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725353#M225289</link>
    <description>&lt;P&gt;True. To each problem its solution.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 07:08:28 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-03-11T07:08:28Z</dc:date>
    <item>
      <title>IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725310#M225260</link>
      <description>&lt;P&gt;I am trying to divide survey respondents into 4 buckets using&amp;nbsp;IF-THEN-ELSE. I'm not having success.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	IF tobacco_pastmo = 0 AND ETOH_pastmo = 0 THEN user_risk = 0;
	ELSE IF tobacco_pastmo = 1 AND ETOH_pastmo = 0 THEN user_risk = 1;
	ELSE IF tobacco_pastmo = 0 AND ETOH_pastmo = 1 THEN user_risk = 2;
	ELSE IF tobacco_pastmo = 1 AND ETOH_pastmo= 1 THEN user_risk = 3;

	/* 	0 = Current MJ only */
	/*	1 = Current MJ + Tobacco user */
	/* 	2 = Current MJ + ETOH user */
	/* 	3 = Current MJ + Tobacco + ETOH user */&lt;/PRE&gt;
&lt;P&gt;A sample dataset and a screen shot of the results using the syntax above are attached.&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 00:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725310#M225260</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2021-03-11T00:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725313#M225261</link>
      <description>Your data shows values of 1/2 but your code is checking for 0/1 values. &lt;BR /&gt;&lt;BR /&gt;Try a PROC FREQ maybe to verify your results?&lt;BR /&gt;&lt;BR /&gt;Proc freq data = have;&lt;BR /&gt;Table tobacco_pastmo*ETOH_pastmo / missing list;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Mar 2021 01:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725313#M225261</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-11T01:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725314#M225262</link>
      <description>&lt;P&gt;The data contains only missing, 1,2, but I think the if statement evaluates it with 0 and 1, so it doesn't get the expected value.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 01:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725314#M225262</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-03-11T01:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725317#M225265</link>
      <description>&lt;P&gt;Sorry, I can't access the website holding your PDF. Please paste an image.&lt;/P&gt;
&lt;P&gt;Also describe what is wrong (your code looks fine) and include the LOG too.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 01:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725317#M225265</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-11T01:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725324#M225271</link>
      <description>&lt;P&gt;Your logic if fine, but you can simplify by changing&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	IF tobacco_pastmo = 0 AND ETOH_pastmo = 0 THEN user_risk = 0;
	ELSE IF tobacco_pastmo = 1 AND ETOH_pastmo = 0 THEN user_risk = 1;
	ELSE IF tobacco_pastmo = 0 AND ETOH_pastmo = 1 THEN user_risk = 2;
	ELSE IF tobacco_pastmo = 1 AND ETOH_pastmo= 1 THEN user_risk = 3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to (assuming etoh_pastmo and tobacco_pastmo have 3 possible values: &lt;EM&gt;&lt;STRONG&gt;missing, 0, and 1:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if nmiss(etoh_pastmo,tobacco_pastmo)=0 then  user_risk=  2*etoh_pastmo + tobacco_pastmo&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But since the data are really: &lt;EM&gt;&lt;STRONG&gt;missing, 1, and 2&lt;/STRONG&gt;&lt;/EM&gt;, then use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if nmiss(etoh_pastmo,tobacco_pastmo)=0 then user_risk=2*(etoh_pastmo-1) + (tobacco_pastmo-1) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Mar 2021 01:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725324#M225271</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-11T01:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725333#M225278</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; Your logic if fine, but you can simplify by changing&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;More compact yes, but simpler? This single line of code is A LOT harder to read and to maintain imho.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 02:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725333#M225278</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-11T02:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725334#M225279</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; Your logic if fine, but you can simplify by changing&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;More compact yes, but simpler? This single line of code is A LOT harder to read and to maintain imho.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I can appreciate that observation.&amp;nbsp; But what if there were a 3rd, (or 4th, etc.) dummy variable, doubling the number of categories with each new variable?&amp;nbsp; At some point, I think the (x + 2y + 4z ...) formulation would look more and more appealing compared to 8, 16, .. IF .. THEN statements.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 03:13:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725334#M225279</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-11T03:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725343#M225284</link>
      <description>Duh. Thanks.</description>
      <pubDate>Thu, 11 Mar 2021 05:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725343#M225284</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2021-03-11T05:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN-ELSE | Multiple Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725353#M225289</link>
      <description>&lt;P&gt;True. To each problem its solution.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 07:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Multiple-Conditions/m-p/725353#M225289</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-11T07:08:28Z</dc:date>
    </item>
  </channel>
</rss>

