<?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: new variable with if then statements in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290598#M59778</link>
    <description>&lt;P&gt;is adding q1 ne . and q2 ne . and q3 ne . to PG's statement the best option?&lt;/P&gt;</description>
    <pubDate>Tue, 09 Aug 2016 23:19:16 GMT</pubDate>
    <dc:creator>starz4ever2007</dc:creator>
    <dc:date>2016-08-09T23:19:16Z</dc:date>
    <item>
      <title>new variable with if then statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290578#M59768</link>
      <description>&lt;P&gt;dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;subj&amp;nbsp; q1&amp;nbsp;&amp;nbsp; q2&amp;nbsp; &amp;nbsp;q3&amp;nbsp;&amp;nbsp; q4&amp;nbsp;&amp;nbsp; q5&amp;nbsp;&amp;nbsp;&amp;nbsp; q_total&amp;nbsp; newvar&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 3.1&amp;nbsp;&amp;nbsp;2.1&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8.2&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 2.1&amp;nbsp;&amp;nbsp;4.1&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11.2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.2&amp;nbsp;&amp;nbsp;1&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.3&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would like to creat a new variable (newvar), where if q1 &amp;lt;=1 and if q2 is &amp;lt;= 1 and if q3 is &amp;lt;=1 and if qtotal is &amp;lt;= 8, then newvar =1 ,&amp;nbsp;otherwise&amp;nbsp;newvar =0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so newvar would look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;newvar&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2016 21:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290578#M59768</guid>
      <dc:creator>starz4ever2007</dc:creator>
      <dc:date>2016-08-09T21:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: new variable with if then statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290580#M59769</link>
      <description>&lt;P&gt;newvar =&amp;nbsp;&lt;SPAN&gt;q1 &amp;lt;=1 and q2 &amp;lt;= 1 and q3 &amp;lt;=1 and qtotal &amp;lt;= 8;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2016 21:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290580#M59769</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-08-09T21:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: new variable with if then statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290583#M59772</link>
      <description>&lt;P&gt;hmm im not getting newvar to equal 1 with that code&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2016 21:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290583#M59772</guid>
      <dc:creator>starz4ever2007</dc:creator>
      <dc:date>2016-08-09T21:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: new variable with if then statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290584#M59773</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats﻿&lt;/a&gt;&amp;nbsp;is being very terse.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;His solution works for what you are doing because SAS treats true results as 1 and false as 0. So Newvar is the result of all of those comparisons, true or false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider if "otherwise newvar=0" includes cases of missing values. Missing are less than any value. So in this specific interest if all of the q variables are missing then newvar would be 1.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2016 21:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290584#M59773</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-09T21:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: new variable with if then statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290598#M59778</link>
      <description>&lt;P&gt;is adding q1 ne . and q2 ne . and q3 ne . to PG's statement the best option?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2016 23:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290598#M59778</guid>
      <dc:creator>starz4ever2007</dc:creator>
      <dc:date>2016-08-09T23:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: new variable with if then statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290603#M59780</link>
      <description>&lt;P&gt;Your logical expression yields true (=1) when q1, q2, q3, or q_total are missing because missing is considered by SAS as inferior to any non-missing value. You can change the expression so that missing values will yield false, as demonstrated:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input subj  q1   q2   q3   q4   q5    q_total;
newvarTrue = q1 &amp;lt;=1 and q2 &amp;lt;= 1 and q3 &amp;lt;=1 and q_total &amp;lt;= 8;
newvarFalse = -q1 &amp;gt;= -11 and -q2 &amp;gt;= -1 and -q3 &amp;gt;= -1 and -q_total &amp;gt;= -8;
datalines;
1       1    3.1  2.1   1    1        8.2
2       1    2.1  4.1   1    3      11.2       
3       1    1.2  1      0    1.1     4.3
4       0      1    0      1    0       2
5       .      1    0      1    0       2
;

proc print; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Add a comment in your code to explain the trick.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 01:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290603#M59780</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-08-10T01:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: new variable with if then statements</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290606#M59781</link>
      <description>&lt;P&gt;thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 02:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-variable-with-if-then-statements/m-p/290606#M59781</guid>
      <dc:creator>starz4ever2007</dc:creator>
      <dc:date>2016-08-10T02:07:24Z</dc:date>
    </item>
  </channel>
</rss>

