<?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: Case Statement Error in Flagging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729401#M226967</link>
    <description>&lt;P&gt;It should read if Loc_No = Prod_Ctr_Num then "N"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case it should be reading&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2102=2102 s a "N" but it is reading it as a "Y"&lt;/P&gt;</description>
    <pubDate>Fri, 26 Mar 2021 14:46:48 GMT</pubDate>
    <dc:creator>Scottie_T</dc:creator>
    <dc:date>2021-03-26T14:46:48Z</dc:date>
    <item>
      <title>Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729387#M226957</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following case statement&lt;/P&gt;&lt;P&gt;case when (m.loc_no = m.Prod_Ctr_Num) or m.Prod_Ctr_Num = '7370'&lt;BR /&gt;then "N"&lt;BR /&gt;else "Y" end as Shares_Flag,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should be read and output like this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Loc_No=2102 = Prod_Ctr_Num = 2102 then "N" .... But the code is not reading this as a N and outputing a "Y"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They are both characters and both are formatted to the same digits. I am lost on why this statement can't read them as the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729387#M226957</guid>
      <dc:creator>Scottie_T</dc:creator>
      <dc:date>2021-03-26T14:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729395#M226962</link>
      <description>&lt;P&gt;I don't understand what your question is.&amp;nbsp; Also what did you mean by this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Loc_No=2102 = Prod_Ctr_Num = 2102 then "N" &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729395#M226962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-26T14:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729401#M226967</link>
      <description>&lt;P&gt;It should read if Loc_No = Prod_Ctr_Num then "N"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case it should be reading&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2102=2102 s a "N" but it is reading it as a "Y"&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729401#M226967</guid>
      <dc:creator>Scottie_T</dc:creator>
      <dc:date>2021-03-26T14:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729405#M226969</link>
      <description>&lt;P&gt;I don't understand your question. It looks like you told it that if the two variables have the same value then the result should be N.&lt;/P&gt;
&lt;P&gt;What is is meaning of "2102=2102"?&amp;nbsp; Are those supposed to be some example values of the variables?&amp;nbsp; If so they look the same to me, but I thought you had character variables.&amp;nbsp; In character variables leading spaces are important in comparison and trailing spaces are not.&amp;nbsp; So this test is false:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'2102' = '   2102'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or are you saying that even if the variables are equal but the value is "2102" the answer should be Y instead of N?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when ( Loc_No = Prod_Ctr_Num  and Loc_no='2101') then 'Y'
  when ( Loc_No = Prod_Ctr_Num) then 'N'
  else '?'
end
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Mar 2021 14:58:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729405#M226969</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-26T14:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729408#M226971</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115585"&gt;@Scottie_T&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following case statement&lt;/P&gt;
&lt;P&gt;case when (m.loc_no = m.Prod_Ctr_Num) or m.Prod_Ctr_Num = '7370'&lt;BR /&gt;then "N"&lt;BR /&gt;else "Y" end as Shares_Flag,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be read and output like this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Loc_No=2102 = Prod_Ctr_Num = 2102 then "N" .... But the code is not reading this as a N and outputing a "Y"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They are both characters and both are formatted to the same digits. I am lost on why this statement can't read them as the same.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Formatted to the same number of characters, not "same digits". Format controls display, not content. If a variable has 10 characters but you assign a format of $4. it only displays 4 characters when printed but the full 10 characters would used for comparisons. You many want to consider examining the assigned Lengths of the variables.&lt;/P&gt;
&lt;P&gt;With character variables an equality condition compares character by character and stops with "not equal" as soon as there is a difference. The longer value compares to a "missing" character and returns not equal for a comparison. &lt;/P&gt;
&lt;P&gt;See this example:&lt;/P&gt;
&lt;PRE&gt;data junk;
   x='2102';
   y='21024567';
   format x y $4.;
   put _all_;
   if x=y then put "The variables are equal";
   Else put y= $10.;
run;&lt;/PRE&gt;
&lt;P&gt;Another possibility depending on how you are looking at your values is that there is leading space in one value not present in the other. The displays using Proc print will usually left justify the text effectively removing the "space" for human eyes but the value is different than what you may see.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 15:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729408#M226971</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-26T15:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729423#M226978</link>
      <description>&lt;P&gt;Please consult at a PROC CONTENTS readout, or equivalent, of your data and inform us if the variables are strings or numeric .&amp;nbsp; I suspect that you are confusing string and numeric variables as well, but its hard to say without you stating.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 15:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729423#M226978</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-03-26T15:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729430#M226981</link>
      <description>&lt;P&gt;I have attached the proc contents of this code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 15:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729430#M226981</guid>
      <dc:creator>Scottie_T</dc:creator>
      <dc:date>2021-03-26T15:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729462#M226994</link>
      <description>&lt;P&gt;Please have a look here&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
length id Loc_No Prod_Ctr_Num $4.;
input id Loc_no Prod_Ctr_Num;
Datalines ;
1 2102 2102
2 3340 7370
3 5590 4370
;
run;
proc sql;
select *,
case when (m.loc_no = m.Prod_Ctr_Num) or m.Prod_Ctr_Num = '7370'
then "N"
else "Y"
end as Shares_Flag from temp m;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output looks as you have wanted.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1616783919009.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56562i12D44970BB422961/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1616783919009.png" alt="Sajid01_0-1616783919009.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thus when&amp;nbsp;&lt;CODE class=" language-sas"&gt;Loc_No and Prod_Ctr&amp;nbsp;are&amp;nbsp;equal&amp;nbsp;you&amp;nbsp;get&amp;nbsp;N,&amp;nbsp;when&amp;nbsp;Prod_Ctr&amp;nbsp;is&amp;nbsp;7370&amp;nbsp;then&amp;nbsp;also&amp;nbsp;there&amp;nbsp;is&amp;nbsp;N.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Are&amp;nbsp;you&amp;nbsp;looking&amp;nbsp;for&amp;nbsp;something&amp;nbsp;different?&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 18:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729462#M226994</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-03-26T18:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729463#M226995</link>
      <description>&lt;P&gt;According to your PROC CONTENTS output, there is no variable LOC_NO in your dataset.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 18:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729463#M226995</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-26T18:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Case Statement Error in Flagging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729501#M227016</link>
      <description>&lt;P&gt;I was renaming over a column with a separate statement so it was not recognizing the two characters as the same. I separated all the calculations out into separate columns and found where the statements were getting confused. Then the case statement worked great it was all about the naming and not writing over the existing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you everyone for your help on this!!&lt;/P&gt;&lt;P&gt;Scottie&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Mar 2021 21:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-Statement-Error-in-Flagging/m-p/729501#M227016</guid>
      <dc:creator>Scottie_T</dc:creator>
      <dc:date>2021-03-26T21:46:32Z</dc:date>
    </item>
  </channel>
</rss>

