<?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: Create a variable based on other vars: If then else if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318327#M69733</link>
    <description>&lt;P&gt;If you have it coded like numbers&amp;gt;&lt;/P&gt;
&lt;P&gt;data aaa;&lt;BR /&gt;input var1 var2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;0 0&lt;BR /&gt;0 1&lt;BR /&gt;1 0&lt;BR /&gt;1 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data aaa;&lt;BR /&gt;set aaa;&lt;BR /&gt;if var1 or var2 then result=1;&lt;BR /&gt; else result=0;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have it coded in strings be careful with comparing longer strings and upper lower cases&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data bbb;&lt;BR /&gt;input var1 $3. var2 $3. ;&lt;BR /&gt;datalines;&lt;BR /&gt;No No&lt;BR /&gt;No Yes&lt;BR /&gt;YesNo&lt;BR /&gt;YesYes&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data bbb;&lt;BR /&gt;set bbb;&lt;BR /&gt;if lowcase(strip(var1))='yes' or lowcase(strip(var2))='yes' then result=1;&lt;BR /&gt;else result=0;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise the logic is quite simple...&lt;/P&gt;</description>
    <pubDate>Mon, 12 Dec 2016 17:18:19 GMT</pubDate>
    <dc:creator>chrej5am</dc:creator>
    <dc:date>2016-12-12T17:18:19Z</dc:date>
    <item>
      <title>Create a variable based on other vars: If then else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318323#M69731</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a variable based on the responses of the two other variables in my dataset. For example, I want to create a new dichotomized var (0=no; 1=yes) called new_var using var1 and var2. If one of the responses is yes, or both of them are yes, then it should be categorized as yes. Ohterwise, it should be no.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried If-then-else-if statement, but it didnt work. Any suggestion would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 16:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318323#M69731</guid>
      <dc:creator>jhs2171</dc:creator>
      <dc:date>2016-12-12T16:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a variable based on other vars: If then else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318326#M69732</link>
      <description>&lt;P&gt;Well, I would do something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  length new_var $5;
  set have;
  new_var="No";&lt;BR /&gt;  if var1="Yes" or var2="Yes" then new_var="Yes";
run;&lt;/PRE&gt;
&lt;P&gt;Seems a bit of a basic question though, are you sure this is what your asking? &amp;nbsp;Could shrink it too:&lt;/P&gt;
&lt;PRE&gt;data want;
  length new_var $5;
  set have;
  new_var=ifc(var1="Yes" or var2="Yes","Yes","No");
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 17:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318326#M69732</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-12T17:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create a variable based on other vars: If then else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318327#M69733</link>
      <description>&lt;P&gt;If you have it coded like numbers&amp;gt;&lt;/P&gt;
&lt;P&gt;data aaa;&lt;BR /&gt;input var1 var2 ;&lt;BR /&gt;datalines;&lt;BR /&gt;0 0&lt;BR /&gt;0 1&lt;BR /&gt;1 0&lt;BR /&gt;1 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data aaa;&lt;BR /&gt;set aaa;&lt;BR /&gt;if var1 or var2 then result=1;&lt;BR /&gt; else result=0;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have it coded in strings be careful with comparing longer strings and upper lower cases&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data bbb;&lt;BR /&gt;input var1 $3. var2 $3. ;&lt;BR /&gt;datalines;&lt;BR /&gt;No No&lt;BR /&gt;No Yes&lt;BR /&gt;YesNo&lt;BR /&gt;YesYes&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data bbb;&lt;BR /&gt;set bbb;&lt;BR /&gt;if lowcase(strip(var1))='yes' or lowcase(strip(var2))='yes' then result=1;&lt;BR /&gt;else result=0;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise the logic is quite simple...&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 17:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318327#M69733</guid>
      <dc:creator>chrej5am</dc:creator>
      <dc:date>2016-12-12T17:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create a variable based on other vars: If then else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318328#M69734</link>
      <description>&lt;P&gt;Yes! Thank you! I had tried something very similar to what you suggested below, but it didnt' work. Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 17:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-variable-based-on-other-vars-If-then-else-if-statement/m-p/318328#M69734</guid>
      <dc:creator>jhs2171</dc:creator>
      <dc:date>2016-12-12T17:22:45Z</dc:date>
    </item>
  </channel>
</rss>

