<?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: How do I correctly use an IF statement to assign new data to a variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300802#M312325</link>
    <description>&lt;P&gt;Thanks so much. &amp;nbsp;I wasn't familiar with using "when" and have, thus, never used it before. &amp;nbsp;However, I can see how it can be useful especially for formatting and readability purposes. &amp;nbsp;All great advice that I really appreciate as I continue to learn.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2016 16:20:07 GMT</pubDate>
    <dc:creator>ELMC</dc:creator>
    <dc:date>2016-09-26T16:20:07Z</dc:date>
    <item>
      <title>How do I correctly use an IF statement to assign new data to a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300687#M312320</link>
      <description>&lt;P&gt;I wrote some code that is only partially executing (below) and I cannot determine why it is not completely working. &amp;nbsp;I am not receiving an error message. &amp;nbsp;Part of the code is simply not filling in the character data that I've specified. &amp;nbsp;Sample data is attached. &amp;nbsp;A little urgent help please:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data &amp;amp;OUTFILE3.;&lt;BR /&gt;set &amp;amp;OUTFILE3.;&lt;/P&gt;&lt;P&gt;LENGTH IMP_JOB2 $30;&lt;/P&gt;&lt;P&gt;if IMP_JOB = "z_Blue Collar"&lt;BR /&gt;and INC_CAT in ("$150k to 199k","$200k to 249k","$250k or More")&lt;BR /&gt;then IMP_JOB2 = "Doctor"; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Correctly executed */&lt;BR /&gt;else if IMP_JOB = "z_Blue Collar"&lt;BR /&gt;and INC_CAT in ("$100k to 149k") &amp;nbsp; &amp;nbsp; &amp;nbsp;/* Either not executing or being overwritten somehow */&lt;BR /&gt;then IMP_JOB2 = "z_White Collar";&lt;BR /&gt;else if IMP_JOB = "z_Blue Collar"&lt;BR /&gt;and INC_CAT = "None"&lt;BR /&gt;then IMP_JOB2 = "Unemployed"; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* 0 records, so uncertain if it executed properly */&lt;BR /&gt;else IMP_JOB2 = IMP_JOB;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 04:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300687#M312320</guid>
      <dc:creator>ELMC</dc:creator>
      <dc:date>2016-09-26T04:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I correctly use an IF statement to assign new data to a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300688#M312321</link>
      <description>&lt;P&gt;Text has to match exactly. You're missing a $ sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"$100k to &lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;$&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;149k"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 04:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300688#M312321</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-26T04:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I correctly use an IF statement to assign new data to a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300711#M312322</link>
      <description>&lt;P&gt;Several tips to help. &amp;nbsp;First, don't post Excel files, they are dangerous, post test data in the form of a datastep in the post. &amp;nbsp;Second use the code window = {i} above the post, so code retains formatting. &amp;nbsp;Then apply some good coding practices to make code readable. &amp;nbsp;Then alter your logic slightly to make it more readbable. &amp;nbsp;Not sure why you have a macro variable as dataset either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data &amp;amp;outfile3.;
  set &amp;amp;outfile3.;
  length imp_job2 $30;
  if imp_job="z_Blue Collar" then do;
    select(inc_cat);
      when ("$150k to 199k","$200k to 249k","$250k or More") imp_job2="Doctor";
      when ("$100k to 149k") imp_job2="z_White Collar";
      when ("None") imp_job2="Unemployed";
      otherwise imp_job2=imp_job;
    end;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Note, I have not added&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;'s fix, as can't see the test data. &amp;nbsp;I would advise that if you intend to use that data for anything, then process it and convert the text to numbers so you can process the data effectively (i.e. do sums and things).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 08:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300711#M312322</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-26T08:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I correctly use an IF statement to assign new data to a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300767#M312323</link>
      <description>&lt;P&gt;BTW&lt;/P&gt;
&lt;P&gt;I strongly recommend not using the&lt;/P&gt;
&lt;P&gt;data &amp;amp;OUTFILE3.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set &amp;amp;OUTFILE3.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with anything except temporary datasets. It is too easy to change a variable such as you INC_CAT in one run (possibly "cleaning" the data) and then no longer have the original vales when needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have traced a "result" that changed from nearly 30% in one year to about 70% in the next back to this&amp;nbsp;dataset reuse&amp;nbsp;and a recode statement that was flipping values such as 0 to 1 and 1 to 0.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 14:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300767#M312323</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-26T14:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I correctly use an IF statement to assign new data to a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300799#M312324</link>
      <description>&lt;P&gt;Thank you for the fix! &amp;nbsp;I guess after looking it over so many times, I ended up overlooking the obvious.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 16:16:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300799#M312324</guid>
      <dc:creator>ELMC</dc:creator>
      <dc:date>2016-09-26T16:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I correctly use an IF statement to assign new data to a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300802#M312325</link>
      <description>&lt;P&gt;Thanks so much. &amp;nbsp;I wasn't familiar with using "when" and have, thus, never used it before. &amp;nbsp;However, I can see how it can be useful especially for formatting and readability purposes. &amp;nbsp;All great advice that I really appreciate as I continue to learn.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 16:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-correctly-use-an-IF-statement-to-assign-new-data-to-a/m-p/300802#M312325</guid>
      <dc:creator>ELMC</dc:creator>
      <dc:date>2016-09-26T16:20:07Z</dc:date>
    </item>
  </channel>
</rss>

