<?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 statement with a combination of variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508013#M72884</link>
    <description>&lt;P&gt;Using&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241271"&gt;@MBlack732&lt;/a&gt; If statements with quotes and correct spelling for varables with samename this works but you want to rethink your formats for the men.&amp;nbsp; Also note I used the upcase on gender incase a user could enter upper or lower case values.&lt;/P&gt;&lt;P&gt;updated for&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; to be shorter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Notes
	GENDER
	M=Male 
	F= Female
	 
	PREGNANCY
	0=never been pregnant
	1=has been or is pregnant
	9=not available
*/

data have;
input name $ pregnancy $ gender $;
cards;
Mary 1 F
Mike 1 m
John 0 M
Ed 0 M
Ann 9 F
Gwen 0 F
;
data want;
	set have;
	gender = upcase(gender);
&amp;nbsp;       if gender = 'M' and pregnancy = '1' then cat=0;&lt;BR /&gt;&amp;nbsp;       else cat = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Sat, 27 Oct 2018 20:52:13 GMT</pubDate>
    <dc:creator>VDD</dc:creator>
    <dc:date>2018-10-27T20:52:13Z</dc:date>
    <item>
      <title>IF THEN statement with a combination of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508004#M72879</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm working with a data set and I'm trying to see if any of the pregnancy responses are invalid based on gender (i.e. male participants should not be recorded as having ever been pregnant).&amp;nbsp;&lt;/P&gt;&lt;P&gt;The values are as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GENDER&lt;/P&gt;&lt;P&gt;M=Male&amp;nbsp;&lt;/P&gt;&lt;P&gt;F= Female&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PREGNANCY&lt;/P&gt;&lt;P&gt;0=never been pregnant&lt;/P&gt;&lt;P&gt;1=has been or is pregnant&lt;/P&gt;&lt;P&gt;9=not available&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I write an IF THEN statement where if the participant is a man and has been pregnant than his category is 0 but any other combination of the two variables is category 1?&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 17:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508004#M72879</guid>
      <dc:creator>MBlack732</dc:creator>
      <dc:date>2018-10-27T17:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN statement with a combination of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508006#M72880</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241271"&gt;@MBlack732&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working with a data set and I'm trying to see if any of the pregnancy responses are invalid based on gender (i.e. male participants should not be recorded as having ever been pregnant).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values are as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;GENDER&lt;/P&gt;
&lt;P&gt;M=Male&amp;nbsp;&lt;/P&gt;
&lt;P&gt;F= Female&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PREGNANCY&lt;/P&gt;
&lt;P&gt;0=never been pregnant&lt;/P&gt;
&lt;P&gt;1=has been or is pregnant&lt;/P&gt;
&lt;P&gt;9=not available&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I write an IF THEN statement where if the participant is a man and has been pregnant than his category is 0 but any other combination of the two variables is category 1?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just put your last sentence in code. You have already formulated the statement, only using non-SAS syntax.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 17:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508006#M72880</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-27T17:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN statement with a combination of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508008#M72881</link>
      <description>&lt;P&gt;I tried this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF pregnancy=1 AND gender=M THEN cat=0;&lt;BR /&gt;ELSE IF pregnancy=9 and gender=M THEN cat=0;&lt;BR /&gt;ELSE IF pregnancy=9 and gender=F THEN cat=0;&lt;BR /&gt;ELSE IF pregnancy=1 and gender=F THEN cat=1;&lt;BR /&gt;ELSE IF pregnacy=0 and gender=F THEN cat=1;&lt;BR /&gt;ELSE IF pregnancy=0 and gender=M THEN cat=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and my log resulted in this error message:&lt;/P&gt;&lt;P&gt;206 IF pregnancy=1 AND gender=M THEN cat=0;&lt;BR /&gt;--&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;207 ELSE IF pregnancy=9 and gender=M THEN cat=0;&lt;BR /&gt;----&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;208 ELSE IF pregnancy=9 and gender=F THEN cat=0;&lt;BR /&gt;----&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;209 ELSE IF pregnancy=1 and gender=F THEN cat=1;&lt;BR /&gt;----&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;210 ELSE IF pregnacy=0 and gender=F THEN cat=1;&lt;BR /&gt;----&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;211 ELSE IF pregnancy=0 and gender=M THEN cat=1;&lt;BR /&gt;----&lt;BR /&gt;180&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 18:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508008#M72881</guid>
      <dc:creator>MBlack732</dc:creator>
      <dc:date>2018-10-27T18:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN statement with a combination of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508010#M72882</link>
      <description>&lt;P&gt;constants are case sensitive while variable operands are case insensitive&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IF pregnancy=1 AND gender=M THEN cat=0;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;should be&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IF pregnancy=1 AND gender=&lt;STRONG&gt;'M'&lt;/STRONG&gt; THEN cat=0;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;change accordingly everywhere&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 18:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508010#M72882</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-27T18:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN statement with a combination of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508012#M72883</link>
      <description>Was that code within a data step? I think that's your issue. &lt;BR /&gt;&lt;BR /&gt;data want; *output data set name;&lt;BR /&gt;set have; *input data;&lt;BR /&gt;&lt;BR /&gt;IF statements (corrected for character variables)&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Sat, 27 Oct 2018 19:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508012#M72883</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-27T19:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN statement with a combination of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508013#M72884</link>
      <description>&lt;P&gt;Using&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241271"&gt;@MBlack732&lt;/a&gt; If statements with quotes and correct spelling for varables with samename this works but you want to rethink your formats for the men.&amp;nbsp; Also note I used the upcase on gender incase a user could enter upper or lower case values.&lt;/P&gt;&lt;P&gt;updated for&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; to be shorter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Notes
	GENDER
	M=Male 
	F= Female
	 
	PREGNANCY
	0=never been pregnant
	1=has been or is pregnant
	9=not available
*/

data have;
input name $ pregnancy $ gender $;
cards;
Mary 1 F
Mike 1 m
John 0 M
Ed 0 M
Ann 9 F
Gwen 0 F
;
data want;
	set have;
	gender = upcase(gender);
&amp;nbsp;       if gender = 'M' and pregnancy = '1' then cat=0;&lt;BR /&gt;&amp;nbsp;       else cat = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 27 Oct 2018 20:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508013#M72884</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-10-27T20:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN statement with a combination of variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508015#M72885</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;&amp;nbsp;Pleasing to note you took time to write down the IF THEN statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just a nit and hint, try to see if those IF THEN's can be further shortened&amp;nbsp;&lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Oct 2018 20:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/IF-THEN-statement-with-a-combination-of-variables/m-p/508015#M72885</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-27T20:13:03Z</dc:date>
    </item>
  </channel>
</rss>

