<?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: proc sql: IF statement not working properly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399622#M278526</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Trailing spaces don't affect a string comparison. Leading spaces do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  A='1 ';
  B='1                                    ';
  C=(A=B);
  putlog C=;
run; 
   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;C=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2017 20:21:28 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2017-09-28T20:21:28Z</dc:date>
    <item>
      <title>proc sql: WHERE statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399606#M278517</link>
      <description>&lt;P&gt;I have a dataset which looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;First_name	Last_name	ID_number	Subject	                        Request_type	        Course_to_add	Section_to_add	CourseCode	Section_ID
Jerry	        Harris	        1178936	        ELA Regents (High School)	Add course/section(s)	EES84H	         1	        EES43X	        1
Marty	        Brown	        8945236	        ELA Regents (High School)	Add course/section(s)	EES84H	         9	        EES43X	        9
Gina	        Frank	        1145623	        ELA Regents (High School)	Add course/section(s)	EES84H	         	        EES43X	        78&lt;/PRE&gt;&lt;P&gt;I'm trying to create a subset of this table&amp;nbsp;(obs where Section_to_add = Section_ID and obs where&amp;nbsp;&lt;SPAN&gt;Section_to_add != Section_ID) using the following:&lt;/SPAN&gt;&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;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE invalid_section AS 
(SELECT first_name,
last_name,
id_number,
Subject, 
Request_Type, 
Course_To_Add,
Section_to_add,
CourseCode,
Section_ID
FROM course_sec
WHERE Section_to_add not = Section_ID AND Request_Type = "Add course/section(s)");
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code runs without errors but doesn't seem to be comparing the two columns as expected, as the results I get are identical to my original dataset regardless of whether course_section = section_id or not.&lt;/P&gt;&lt;P&gt;SAS doesn't return any errors or warnings, and the notes are all normal (i.e. Table abc created with x rows and y columns).&lt;/P&gt;&lt;P&gt;Both columns are the same datatype and I've tried a few variations of this (switching the order of the columns, using ne instead of not =, using = instead of not &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; to no avail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm stumped. &amp;nbsp;Any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399606#M278517</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-09-28T20:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399608#M278518</link>
      <description>&lt;P&gt;Your code refers to a variable Course_Section which does not exist in your data.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399608#M278518</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-28T20:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399609#M278519</link>
      <description>&lt;P&gt;that was a typo in the post - not my actual code - it's corrected now&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399609#M278519</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-09-28T20:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399613#M278520</link>
      <description>&lt;P&gt;There may be (or may not be) trailing blanks, try something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WHERE trim(Section_to_add) not = trim(Section_ID) AND trim(Request_Type) = "Add course/section(s)"&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399613#M278520</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-28T20:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399615#M278521</link>
      <description>&lt;P&gt;The word "not" sometimes gets interpreted in funny ways.&amp;nbsp; Try switching the conditions on either side of "AND" within the WHERE clause.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399615#M278521</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-28T20:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399618#M278522</link>
      <description>&lt;P&gt;The code you provided works fine, you must have done something else.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input (FIRST_NAME 	LAST_NAME	ID_NUMBER	  REQUEST_TYPE	        COURSE_TO_ADD	SECTION_TO_ADD	COURSECODE	SECTION_ID) (:&amp;amp; $50.);
cards;
Jerry          Harris          1178936      Add course/section(s)   EES84H           1          EES43X          1
Marty          Brown            8945236     Add course/section(s)   EES84H           9          EES43X          9
Gina          Frank            1145623      Add course/section(s)   EES84H           2          EES43X          78
run; 
         
proc sql;      
  create table INVALID_SECTION as
  select FIRST_NAME
        ,LAST_NAME
        ,ID_NUMBER
        ,REQUEST_TYPE 
        ,COURSE_TO_ADD
        ,SECTION_TO_ADD
        ,COURSECODE
        ,SECTION_ID
  from HAVE
  where SECTION_TO_ADD ne SECTION_ID 
    and REQUEST_TYPE   eq "Add course/section(s)";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;FIRST_NAME&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;LAST_NAME&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;ID_NUMBER&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;REQUEST_TYPE&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;COURSE_TO_ADD&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;SECTION_TO_ADD&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;COURSECODE&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;SECTION_ID&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Gina&lt;/TD&gt;
&lt;TD class="l data"&gt;Frank&lt;/TD&gt;
&lt;TD class="l data"&gt;1145623&lt;/TD&gt;
&lt;TD class="l data"&gt;Add course/section(s)&lt;/TD&gt;
&lt;TD class="l data"&gt;EES84H&lt;/TD&gt;
&lt;TD class="l data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;EES43X&lt;/TD&gt;
&lt;TD class="l data"&gt;78&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399618#M278522</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-09-28T20:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399619#M278523</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Unless the data was read in differently and there are trailing blanks somewhere in the data being used by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88546"&gt;@LizGagne&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399619#M278523</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-28T20:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399620#M278524</link>
      <description>&lt;P&gt;There seems to be leading blanks in column section_to_add. Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;WHERE left(Section_to_add) ne left(Section_ID) AND Request_Type = "Add course/section(s)"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399620#M278524</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-28T20:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399621#M278525</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;- tried your code, still getting the same results. &amp;nbsp;I hadn't considered trailing blanks though, so still a good thing to point out.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399621#M278525</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-09-28T20:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399622#M278526</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;Trailing spaces don't affect a string comparison. Leading spaces do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  A='1 ';
  B='1                                    ';
  C=(A=B);
  putlog C=;
run; 
   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;C=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399622#M278526</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-09-28T20:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399623#M278527</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;- tried your suggestions - got the same results.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399623#M278527</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-09-28T20:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399624#M278528</link>
      <description>&lt;P&gt;You've cracked the case! &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks people of the internet for, once again, solving my problems.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399624#M278528</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-09-28T20:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399625#M278529</link>
      <description>&lt;P&gt;Well spotted.&lt;/P&gt;
&lt;P&gt;It's much better to clean the data and remove these leading spaces in the table though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399625#M278529</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-09-28T20:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399627#M278530</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88546"&gt;@LizGagne&lt;/a&gt;&amp;nbsp;Can you change the title of this post? I don't see any IF statement here.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399627#M278530</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-09-28T20:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: IF statement not working properly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399634#M278531</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; done.</description>
      <pubDate>Thu, 28 Sep 2017 20:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-WHERE-statement-not-working-properly/m-p/399634#M278531</guid>
      <dc:creator>LizGagne</dc:creator>
      <dc:date>2017-09-28T20:51:32Z</dc:date>
    </item>
  </channel>
</rss>

