<?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: Simple If Else Data Step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581443#M165259</link>
    <description>&lt;P&gt;There you go. Seems there was an error in my previous code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input SELECT_FIRST $ ATTR_FIRST $;
infile datalines dlm=',' dsd;
datalines;
Bill, 
Gary,Robert
Thomas,
,
Thomas,Thomas
Simon,
,
Simon,Bill
;

data want;
    set have;
	length select_first_v2 $50 attr_first_v2 $50;
    if SELECT_FIRST=' ' and ATTR_FIRST=' ' then do;
        select_first_v2 = 'NA';
        attr_first_v2 = 'NA';
    end;

    else if SELECT_FIRST=' ' and ATTR_FIRST ne ' ' then do;
        select_first_v2 = ATTR_FIRST;
        attr_first_v2 = ATTR_FIRST;
    end;

    else if SELECT_FIRST ne ' ' and ATTR_FIRST=' ' then do;
        select_first_v2 = SELECT_FIRST;
        attr_first_v2 = SELECT_FIRST;       
    end;

    else do;
        select_first_v2 = SELECT_FIRST;
        attr_first_v2 = ATTR_FIRST;     
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Aug 2019 15:11:45 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-08-15T15:11:45Z</dc:date>
    <item>
      <title>Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581417#M165248</link>
      <description>&lt;P&gt;I cannot describe how idiotic I feel not being able to do this. I have two columns (SELECT_FIRST and ATTR_FIRST) they can both be filled, both be empty, or one empty and the other not. I want to add two new columns (denoted with _V2 ). I want this code to say if both are empty then make the two new columns say 'NA'. If SELECT_FIRST is empty but ATTR_FIRST is not, then add Make both columns the value is ATTR_FIRST. Likewise if ATTR_FIRST is empty then make both columns the value of SELECT_FIRST. If both are filled then make each new column equal to their respective column. Any and all help would be much appreciated!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;FONT&gt;DATA TMP7DAY.ATT_EXHIBIT_V2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SET TMP7DAY.ATT_EXHIBIT;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IF missing(&lt;FONT&gt;SELECT_FIRST&lt;/FONT&gt;) AND missing(&lt;FONT&gt;ATTR_FIRST&lt;/FONT&gt;) THEN SELECT_FIRST_V2 = 'NA' AND ATTR_FIRST_V2 = 'NA';&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ELSE IF missing(SLCT_ID) THEN SELECT_FIRST_V2 = ATTR_FIRST;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ELSE IF missing(ATRBT_ID) THEN ATTR_FIRST_V2 = SELECT_FIRST;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ELSE SELECT_FIRST_V2 = SELECT_FIRST AND ATTR_FIRST_V2 = ATTR_FIRST;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; RUN;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 14:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581417#M165248</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2019-08-15T14:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581420#M165250</link>
      <description>&lt;P&gt;Modifying your own code..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input SELECT_FIRST $ ATTR_FIRST $;
datalines;
. 1
2 .
. .
3 4
;

data want;
    set have;
    if SELECT_FIRST=' ' and ATTR_FIRST=' ' then do;
        select_first_v2 = 'NA';
        attr_first_v2 = 'NA';
    end;

    else if SELECT_FIRST=' ' and ATTR_FIRST ne . then do;
        select_first_v2 = ATTR_FIRST;
        attr_first_v2 = ATTR_FIRST;
    end;

    else if SELECT_FIRST ne ' ' and ATTR_FIRST=. then do;
        select_first_v2 = SELECT_FIRST;
        attr_first_v2 = SELECT_FIRST;       
    end;

    else do;
        select_first_v2 = SELECT_FIRST;
        attr_first_v2 = ATTR_FIRST;     
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Aug 2019 14:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581420#M165250</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-15T14:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581422#M165251</link>
      <description>&lt;P&gt;Do the variables&amp;nbsp;&lt;SPAN&gt;ATTR_FIRST and&amp;nbsp;SELECT_FIRST contain boolean true/false values like the values you are assigning to&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;SELECT_FIRST_V2&amp;nbsp;to in the first THEN clause and the terminal ELSE clause?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 14:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581422#M165251</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-15T14:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581432#M165253</link>
      <description>&lt;P&gt;Don't know where your reply went, but you can set an appropriate length for you created v2 variables like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length select_first_v2 $50 attr_first_v2 $50;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Aug 2019 14:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581432#M165253</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-15T14:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581433#M165254</link>
      <description>The values are names. So one row as the two values in the original columns Bill and Robert then I want there new columns to be Bill and Robert. But if its just Bill and 'Empty' then I want both new columns to be Bill.</description>
      <pubDate>Thu, 15 Aug 2019 14:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581433#M165254</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2019-08-15T14:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581434#M165255</link>
      <description>&lt;P&gt;I don't knew where it went either. But I ran the code again and saw that it actually doesn't work. Values in the new columns are still empty when they shouldn't be. Also how would you set length when the strings can be any length?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 15:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581434#M165255</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2019-08-15T15:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581435#M165256</link>
      <description>&lt;P&gt;Ok.&amp;nbsp; Please post some example of what your data looks like. Makes it much easier to provide a usable code answer.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 15:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581435#M165256</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-15T15:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581441#M165258</link>
      <description>&lt;P&gt;&amp;nbsp; &amp;nbsp; SELECT_FIRST | ATTR_FIRST&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Bill&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Gary &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Robert&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Thomas&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Thomas &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Thomas&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Simon&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Simon &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Bill&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 15:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581441#M165258</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2019-08-15T15:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581443#M165259</link>
      <description>&lt;P&gt;There you go. Seems there was an error in my previous code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input SELECT_FIRST $ ATTR_FIRST $;
infile datalines dlm=',' dsd;
datalines;
Bill, 
Gary,Robert
Thomas,
,
Thomas,Thomas
Simon,
,
Simon,Bill
;

data want;
    set have;
	length select_first_v2 $50 attr_first_v2 $50;
    if SELECT_FIRST=' ' and ATTR_FIRST=' ' then do;
        select_first_v2 = 'NA';
        attr_first_v2 = 'NA';
    end;

    else if SELECT_FIRST=' ' and ATTR_FIRST ne ' ' then do;
        select_first_v2 = ATTR_FIRST;
        attr_first_v2 = ATTR_FIRST;
    end;

    else if SELECT_FIRST ne ' ' and ATTR_FIRST=' ' then do;
        select_first_v2 = SELECT_FIRST;
        attr_first_v2 = SELECT_FIRST;       
    end;

    else do;
        select_first_v2 = SELECT_FIRST;
        attr_first_v2 = ATTR_FIRST;     
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 15:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581443#M165259</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-15T15:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581445#M165260</link>
      <description>Thank you so much!!! When I first wrote this I had no idea I had to do multiple If/Then/Do/End Statements, it makes it much easier to understand. I really appreciate your help!!!!!</description>
      <pubDate>Thu, 15 Aug 2019 15:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581445#M165260</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2019-08-15T15:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581446#M165261</link>
      <description>&lt;P&gt;Anytime, glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 15:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581446#M165261</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-15T15:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If Else Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581447#M165262</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279427"&gt;@mhoward2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The values are names. So one row as the two values in the original columns Bill and Robert then I want there new columns to be Bill and Robert. But if its just Bill and 'Empty' then I want both new columns to be Bill.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So it doesn't sound like you need to use IF/THEN.&amp;nbsp; Just use COALESCEC() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_first = coalescec(first,second);
new_second = coalescec(second,first);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also it is not clear why you want to put 'NA' instead of leaving the values empty, this is SAS and not R. But if you do then just include that as a third argument to the COALESCEC() function calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_first = coalescec(first,second,'NA');
new_second = coalescec(second,first,'NA');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Aug 2019 15:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simple-If-Else-Data-Step/m-p/581447#M165262</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-15T15:19:43Z</dc:date>
    </item>
  </channel>
</rss>

