<?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: Make a new variable from an existing variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540257#M149002</link>
    <description>&lt;P&gt;What does&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cigcur eq 1 or 2
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;mean?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will interpret the OR as a binary boolean operator.&amp;nbsp; No matter what value CIGUR has it will always be TRUE since the value to right of the OR is always true.&amp;nbsp; (SAS considers and number that is not zero or missing as TRUE).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you mean:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cigcur in (1 2)&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Mar 2019 21:54:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-03-04T21:54:55Z</dc:date>
    <item>
      <title>Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540240#M148994</link>
      <description>&lt;P&gt;I want to make a new variable from conditions of existing categorical variables in my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname research "/home/mariamon0/";&lt;/P&gt;&lt;P&gt;data tobacco_;&lt;BR /&gt;set research.tobacco_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;these are the conditions:&lt;BR /&gt;if cigcur eq 1 or 2&lt;BR /&gt;if bidicur eq 1 or 2&lt;BR /&gt;if cigsmoker_new eq 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want my new variable to be LCuser&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how do I go about doing this?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 21:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540240#M148994</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2019-03-04T21:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540242#M148996</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;these are the conditions:&lt;/P&gt;
&lt;P&gt;if cigcur eq 1 or 2&lt;BR /&gt;if bidicur eq 1 or 2&lt;BR /&gt;if cigsmoker_new eq 0&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you mean&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if cigcur eq 1 or 2 &lt;FONT color="#FF0000"&gt;AND&lt;/FONT&gt;&lt;BR /&gt;if bidicur eq 1 or 2 &lt;FONT color="#FF0000"&gt;AND&lt;/FONT&gt;&lt;BR /&gt;if cigsmoker_new eq 0?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or something else?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and I want my new variable to be LCuser&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you want this to be YES or NO, or 0 or 1, or something else?&lt;BR /&gt;&lt;BR /&gt;Can you give us the &lt;STRONG&gt;complete&lt;/STRONG&gt; logic you want to follow?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 21:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540242#M148996</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-04T21:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540250#M149000</link>
      <description>&lt;P&gt;Yes all of those conditions must be there. I want the new variable LCuser to have all of these conditions&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;cigcur eq 1 or 2&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;AND&lt;/FONT&gt;&lt;BR /&gt;&lt;SPAN&gt;bidicur eq 1 or 2&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;AND&lt;/FONT&gt;&lt;BR /&gt;&lt;SPAN&gt;cigsmoker_new eq 0&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 21:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540250#M149000</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2019-03-04T21:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540257#M149002</link>
      <description>&lt;P&gt;What does&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cigcur eq 1 or 2
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;mean?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will interpret the OR as a binary boolean operator.&amp;nbsp; No matter what value CIGUR has it will always be TRUE since the value to right of the OR is always true.&amp;nbsp; (SAS considers and number that is not zero or missing as TRUE).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you mean:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cigcur in (1 2)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2019 21:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540257#M149002</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-04T21:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540258#M149003</link>
      <description>&lt;P&gt;Ok yes I wasn't aware of that. I want that variable to choose either the option 1 or the option 2. so yes I mean&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;cigcur &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;bidicur in (1 2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cigsmoker_new eq 0&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 21:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540258#M149003</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2019-03-04T21:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540259#M149004</link>
      <description>&lt;P&gt;&lt;SPAN&gt;cigcur eq 1 or 2&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;AND&lt;/FONT&gt;&lt;BR /&gt;&lt;SPAN&gt;bidicur eq 1 or 2&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;AND&lt;/FONT&gt;&lt;BR /&gt;&lt;SPAN&gt;cigsmoker_new eq 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;basically I want the new variable LCuser to have the following conditions&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if the users cigcur said 1 or 2, if the bidicur users said 1 or 2 and if the cigsmokernew said 0.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 22:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540259#M149004</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2019-03-04T22:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540262#M149006</link>
      <description>&lt;P&gt;&lt;SPAN&gt;basically I want the new variable LCuser to have the following conditions&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if the users cigcur said 1 or 2, if the bidicur users said 1 or 2 and if the cigsmokernew said 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do I do if statements?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Or&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Lcusrer=if the users cigcur said 1 or 2, if the bidicur users said 1 or 2 and if the cigsmokernew said 0;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 22:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540262#M149006</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2019-03-04T22:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540280#M149012</link>
      <description>&lt;P&gt;yes I would have to use in.&lt;/P&gt;&lt;P&gt;not sure what the exact coding should be together&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 22:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540280#M149012</guid>
      <dc:creator>mariamon0</dc:creator>
      <dc:date>2019-03-04T22:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Make a new variable from an existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540299#M149023</link>
      <description>&lt;P&gt;You have an IF but you don't say what you want to happen when the condition is true.&lt;/P&gt;
&lt;P&gt;There are two types of IF statements in SAS.&lt;/P&gt;
&lt;P&gt;There is the more traditional programming structure of the IF/THEN.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if condition then statement;&lt;/PRE&gt;
&lt;P&gt;So when the condition after IF is true the statement after THEN executes.&amp;nbsp; Typically this is an assignment statement. like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if cigsmoker_new eq 0 then LCuser=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The other type of IF statement in SAS takes the form:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if condition ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is called a subsetting IF statement.&amp;nbsp; If the condition is true then the data step iteration continues.&amp;nbsp; If it is false then the data step iteration stops.&amp;nbsp; None of the rest of the code in the data step executes, including any implicit OUTPUT at the end.&amp;nbsp; So this is equivalent to this IF/THEN statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not condition then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So what you want is to make a dataset that had only observations that satisfy ALL of the conditions then you could use three subsetting if statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if cigcur in (1 2);
  if bidicur in (1 2);
  if cigsmoker_new eq 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to make a new variable named LCuser and set it to one if ANY of your three conditions is true then you could use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  LCuser=0;
  if cigcur in (1 2) then LCuser=1;
  if bidicur in (1 2) then LCuser=1;
  if cigsmoker_new eq 0 then LCuser=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could just make one IF statement and combine the conditions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  LCuser=0;
  if cigcur in (1 2) or  bidicur in (1 2) or cigsmoker_new eq 0 then LCuser=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you combine them with AND instead of OR then LCUser will be 1 only when ALL of the conditions are true instead of when ANY of them is true.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 00:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Make-a-new-variable-from-an-existing-variable/m-p/540299#M149023</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-05T00:36:26Z</dc:date>
    </item>
  </channel>
</rss>

