<?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 If statement is not giving the correct result. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898729#M40000</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am running a code and it runs without any error or warning but it does not give the correct output result. I am trying to find if the account number is coming for the first time in the table then mark it as 1 but the output results does not show 1 in any records. Here is my code.&lt;/P&gt;
&lt;P&gt;data Trace_result_Flag;&lt;BR /&gt;set Trace_result_Sort;&lt;BR /&gt;by 'ACC NO'n Trace_dt;&lt;BR /&gt;if first.'ACC NO'n then Trace_Flag = 1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Even if the acc no is repeating, it does not flag it as 1. Please suggest.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Oct 2023 10:55:12 GMT</pubDate>
    <dc:creator>Sandeep77</dc:creator>
    <dc:date>2023-10-16T10:55:12Z</dc:date>
    <item>
      <title>If statement is not giving the correct result.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898729#M40000</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am running a code and it runs without any error or warning but it does not give the correct output result. I am trying to find if the account number is coming for the first time in the table then mark it as 1 but the output results does not show 1 in any records. Here is my code.&lt;/P&gt;
&lt;P&gt;data Trace_result_Flag;&lt;BR /&gt;set Trace_result_Sort;&lt;BR /&gt;by 'ACC NO'n Trace_dt;&lt;BR /&gt;if first.'ACC NO'n then Trace_Flag = 1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Even if the acc no is repeating, it does not flag it as 1. Please suggest.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 10:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898729#M40000</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-10-16T10:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: If statement is not giving the correct result.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898731#M40001</link>
      <description>&lt;P&gt;Please show us a portion of the data, as working SAS data step code.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 10:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898731#M40001</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-16T10:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: If statement is not giving the correct result.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898732#M40002</link>
      <description>&lt;P&gt;Data Trace_result_Flag; &lt;BR /&gt;infile cards expandtabs; &lt;BR /&gt;input 'ACC NO'n LIMA_result $ Trace_Flag;&lt;BR /&gt;datalines ; &lt;BR /&gt;1014824 NEG .&lt;BR /&gt;1014824 NEG .&lt;BR /&gt;1014824 NEG .&lt;BR /&gt;1064951 LAS .&lt;BR /&gt;1064951 LAS .&lt;BR /&gt;1064951 LAS .&lt;BR /&gt;1064951 LAS .&lt;BR /&gt;1064951 LAS .&lt;BR /&gt;1064951 LAS .&lt;BR /&gt;1064951 LAS .&lt;BR /&gt;; &lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 11:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898732#M40002</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-10-16T11:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: If statement is not giving the correct result.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898735#M40004</link>
      <description>&lt;P&gt;It does not help when the variable names and data set names change from your original post, to the later post. Could you please show us code and data that have consistent variable names and data set names?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 11:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898735#M40004</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-16T11:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: If statement is not giving the correct result.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898737#M40005</link>
      <description>&lt;P&gt;Also, from now on, &lt;FONT color="#FF0000"&gt;please please please&lt;/FONT&gt; show us the log, all of it for the DATA step that has a problem. Even if you think there is nothing in there of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, as I have played around with your problem, there is indeed a problem indicated in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;226   data Trace_result_Flag2;
227   set Trace_result_flag;
228   by 'ACC NO'n;
229   if first.'ACC NO'n then Trace_Flag = 1;
230   run;

&lt;FONT color="#FF0000"&gt;NOTE: Variable 'first.''ACC NO''n'n is uninitialized.&lt;/FONT&gt;
NOTE: There were 10 observations read from the data set WORK.TRACE_RESULT_FLAG2.
NOTE: The data set WORK.TRACE_RESULT_FLAG2 has 10 observations and 3 variables.
NOTE: Compressing data set WORK.TRACE_RESULT_FLAG2 increased size by 100.00 percent.
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.03 seconds
&lt;/PRE&gt;
&lt;P&gt;Try this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 'first.ACC NO'n then Trace_Flag = 1;
&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;You would make your coding much easier, with fewer opportunities for typing errors or syntax errors, if you used variable names such as &lt;FONT face="courier new,courier"&gt;acc_no&lt;/FONT&gt; instead of &lt;FONT face="courier new,courier"&gt;'ACC NO'n&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 12:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898737#M40005</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-16T12:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: If statement is not giving the correct result.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898768#M40010</link>
      <description>Cheers! 'first.Acc No'n worked. Actually, I generated a file from a dataset which required the format as Acc No and later on I was told to add few more information. Otherwise I would have kept it as acc_no. Thanks a lot!!</description>
      <pubDate>Mon, 16 Oct 2023 12:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898768#M40010</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-10-16T12:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: If statement is not giving the correct result.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898784#M40013</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Cheers! 'first.Acc No'n worked. Actually, I generated a file from a dataset which required the format as Acc No and later on I was told to add few more information. Otherwise I would have kept it as acc_no. Thanks a lot!!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Variable names never need to have a blank or other fancy stuff in them. If a nice version of a name is required for printing (this includes export to excel) put the text into a label.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 13:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/If-statement-is-not-giving-the-correct-result/m-p/898784#M40013</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-10-16T13:31:38Z</dc:date>
    </item>
  </channel>
</rss>

