<?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: Adding a new column to find if the value is repeated again. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870581#M38550</link>
    <description>&lt;P&gt;Thank you all!&lt;/P&gt;</description>
    <pubDate>Wed, 19 Apr 2023 15:30:47 GMT</pubDate>
    <dc:creator>Sandeep77</dc:creator>
    <dc:date>2023-04-19T15:30:47Z</dc:date>
    <item>
      <title>Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870557#M38537</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;I have a dataset which has repeated reference_number. I do not want to delete anything but just want to add a new column which can show 1 if the reference_number is repeaded or else 0. Can you please suggest how can I do that. I have used the below code. This highlight the first time reference_number as 0 and the repeated reference_number as 1. I want if the reference_number is not repeated then 0 and if repeated then 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data repeated_accounts;
set Equifax_files;
if lag(reference_number)=reference_number then repeat_flag=1;
else repeat_flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 14:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870557#M38537</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-04-19T14:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870561#M38539</link>
      <description>&lt;P&gt;It sounds like your data is sorted by reference_number.&amp;nbsp; If I'm understanding your goal, you can do it like (untested):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data repeated_accounts;
  set Equifax_files;
  by reference_number ;
  flag = NOT (first.reference_number and last.reference_number) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 14:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870561#M38539</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-04-19T14:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870562#M38540</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* data */
data Equifax_files;
input reference_number $ 1. @@;
if reference_number;
cards;
123456673399822267234
;
run;
proc print;
run;

/*process*/

proc sort data=Equifax_files;
  by reference_number;
run;

data Equifax_files;
  set Equifax_files;
  by reference_number;

  marker = not first.reference_number;
run;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 14:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870562#M38540</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-19T14:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870570#M38544</link>
      <description>&lt;P&gt;Example before and result desired.&lt;/P&gt;
&lt;P&gt;Since your LAG attempt, which doesn't behave as you want because of the nature of LAG, would only have a chance of working if the reference is sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input ref;
datalines;
1
1
1
2
3
3
4
; 


data want;
  set example;
  by ref;
  flag= not(first.ref);
run;&lt;/PRE&gt;
&lt;P&gt;LAG, and DIF, are queue functions. So when you use IF lag() the "lagged" value is the last time the IF was true, not the previous record.&lt;/P&gt;
&lt;P&gt;To use Lag you would do something like:&lt;/P&gt;
&lt;PRE&gt;data repeated_accounts;
set Equifax_files;
Lref = lag(Reference_number);
if lfref=reference_number then repeat_flag=1;
else repeat_flag=0;
drop lref;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 14:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870570#M38544</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-19T14:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870573#M38546</link>
      <description>Thank you but this is also showing in the same way I was getting. First ref_number as 0 and when it was repeated it was showing as 1. I want if there are more than 1 same reference number then 1 and if it is unique then 0.</description>
      <pubDate>Wed, 19 Apr 2023 15:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870573#M38546</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-04-19T15:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870576#M38547</link>
      <description>Thank you but it still shows as the first reference_number as 0 and the repeated reference_number as 1. I want if the reference_number is repeated then put it as 1 or else 0. So that I can filter out 0 and conclude them as they are not repeated and unique reference_numbers from the data.</description>
      <pubDate>Wed, 19 Apr 2023 15:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870576#M38547</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-04-19T15:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870578#M38548</link>
      <description>&lt;P&gt;If you want a flag that indicates if the reference number is UNIQUE (appears only in one observation) and the data is sorted then you need to test both the FIRST. and the LAST. flags.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this data step will create a flag variable UNIQUE that will be 1 (TRUE) when this is the only observation with that value and 0 (FALSE) when it is any of multiple observations with the same value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
   by ref_no;
   unique = first.ref_no and last.ref_no ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Apr 2023 15:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870578#M38548</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-19T15:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870579#M38549</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;'s answer seems to be doing the job, i.e.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;marker = not (first.reference_number and last.reference_number);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 15:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870579#M38549</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-04-19T15:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870581#M38550</link>
      <description>&lt;P&gt;Thank you all!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 15:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870581#M38550</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-04-19T15:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column to find if the value is repeated again.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870588#M38551</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;Thank you but it still shows as the first reference_number as 0 and the repeated reference_number as 1. I want if the reference_number is repeated then put it as 1 or else 0. So that I can filter out 0 and conclude them as they are not repeated and unique reference_numbers from the data.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I submit that your descriptions need to include example DATA and desired result.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 15:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Adding-a-new-column-to-find-if-the-value-is-repeated-again/m-p/870588#M38551</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-19T15:51:32Z</dc:date>
    </item>
  </channel>
</rss>

