<?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: Compare the character values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919712#M362270</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your message. Just 2 : X means cancelled event.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So does this means (a) there are no instances of more than 2 records for a given NO/CODE_2/DATE combination, and (b) ALL instances of exactly two records for a given combination represent instances of an event and its cancellation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, then all you really want to do is keep only the singletons, yes?&amp;nbsp; That's what this code does.&amp;nbsp; And you would not need to compare character values (assuming data are sorted by NO/CODE_2/DATE):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by no code_2 date;
  if first.date=1 and last.date=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Mar 2024 00:52:01 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-03-11T00:52:01Z</dc:date>
    <item>
      <title>Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919700#M362265</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using the group by statement in proc sql by NO Code_2 and DATE.&lt;/P&gt;
&lt;P&gt;By this key I would like to delete the CD that have only "X" difference (XTIN et TIN), beacause it is the same events.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know some option to count the value as the same if only one letter is different ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The file is joined.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASdevAnneMarie_0-1710108892155.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94545i736CBFF72F583A79/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASdevAnneMarie_0-1710108892155.png" alt="SASdevAnneMarie_0-1710108892155.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Sun, 10 Mar 2024 22:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919700#M362265</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2024-03-10T22:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919701#M362266</link>
      <description>&lt;P&gt;Are the records in your data set always in pairs, with value without an X (for example TIN) coming before the value with the X (for example, XTIN)? Could there ever be a group of 3 records?&lt;/P&gt;</description>
      <pubDate>Sun, 10 Mar 2024 22:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919701#M362266</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-10T22:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919703#M362267</link>
      <description>Thank you for your message. Just 2 : X means cancelled event.</description>
      <pubDate>Sun, 10 Mar 2024 22:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919703#M362267</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2024-03-10T22:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919707#M362268</link>
      <description>&lt;P&gt;Why not just delete the observations where CD starts with X?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easy with an IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if cd =: 'X' then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Harder with a WHERE statement (or in SQL code) since you cannot use the : modifier to do trimmed comparisons.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where char(cd,1) ne 'X'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Mar 2024 23:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919707#M362268</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-10T23:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919708#M362269</link>
      <description>&lt;P&gt;To just delete any cancelled event a where clause would do. If you want to keep cancelled events without a matching event on the same date then code as below should work.&lt;/P&gt;
&lt;P&gt;The last row in below data contains the case where there is a cancelled event (XTINK) without a matching event.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm=',' dsd truncover;
  input NO $ Code_2 $ DATE:ddmmyy10. CD$;
  format date date9.;
  some_other_var=_n_;
  datalines;
B17,214,18/07/2019,TIN
B17,214,6/08/2019,TIN
B17,214,6/08/2019,XTIN
B17,214,10/12/2019,TINK
B17,214,10/12/2019,XTINK
MK2,300,18/10/2019,TIN
MK2,300,19/10/2019,MIN
MK2,300,19/10/2019,XMIN
MK2,300,21/10/2019,PAP
MK2,300,22/10/2019,PAK
MK2,300,01/12/2019,XTINK
;

/* option 1 */
proc sql;
  create table want_1 as
  select *, count(*) as cnt
  from have
  group by no,code_2,date
  having cnt=1 or cnt&amp;gt;1 and upcase(substr(cd,1,1)) ne 'X'
  ;
quit;

/* option 2 */
proc sort data=have out=inter;
  by no Code_2 date;
run;
data want_2;
  set inter;
  by no Code_2 date;
  if not first.date and upcase(substr(cd,1,1)) = 'X' then delete;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Mar 2024 23:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919708#M362269</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-10T23:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919712#M362270</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your message. Just 2 : X means cancelled event.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So does this means (a) there are no instances of more than 2 records for a given NO/CODE_2/DATE combination, and (b) ALL instances of exactly two records for a given combination represent instances of an event and its cancellation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, then all you really want to do is keep only the singletons, yes?&amp;nbsp; That's what this code does.&amp;nbsp; And you would not need to compare character values (assuming data are sorted by NO/CODE_2/DATE):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by no code_2 date;
  if first.date=1 and last.date=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2024 00:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919712#M362270</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-11T00:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919748#M362280</link>
      <description>Thank you, Tom, but I would like to delete the double line (with XMIN et MIN) beacause it is cancelled event (if on the same date).</description>
      <pubDate>Mon, 11 Mar 2024 12:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919748#M362280</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2024-03-11T12:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919751#M362282</link>
      <description>&lt;P&gt;It was at least for me not clear from your description that you want to delete ALL the highlighted rows. Below should do this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm=',' dsd truncover;
  input NO $ Code_2 $ DATE:ddmmyy10. CD$;
  format date date9.;
  some_other_var=_n_;
  datalines;
B17,214,18/07/2019,TIN
B17,214,6/08/2019,TIN
B17,214,6/08/2019,XTIN
B17,214,10/12/2019,TINK
B17,214,10/12/2019,XTINK
MK2,300,18/10/2019,TIN
MK2,300,19/10/2019,MIN
MK2,300,19/10/2019,XMIN
MK2,300,21/10/2019,PAP
MK2,300,22/10/2019,PAK
;

proc sql;
/*  create table want_1 as*/
  select l.*
  from have l 
  left join (select no,code_2,date,substr(cd,2) as _cd from have where upcase(substr(cd,1,1))='X') r
  on l.no=r.no and l.code_2=r.code_2 and l.date=r.date
  where missing(r._cd)
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2024 12:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919751#M362282</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-11T12:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919968#M362337</link>
      <description>&lt;P&gt;&lt;BR /&gt;Can you try this?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sort data = have;
    by no code_2 date cd;
run;

data want;
    do until(last.date);
      set have;
      by no code_2 date;
     If cd =: 'X' then flag=1;
   end;
   do until(last.date);
     set have;
     by no code_2 date;
     If flag then continue;
     output;
  end;
  flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Mar 2024 17:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919968#M362337</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-12T17:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919979#M362341</link>
      <description>&lt;P&gt;I suspect that code may have an issue because of the curly quotes around the X in the line starting "If cd =: " . Look closely, they are not the simple double quote used in SAS for character values: "&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464333"&gt;@Mazi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;Can you try this?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;proc sort data = have;
    by no code_2 date cd;
run;

data want;
    do until(last.date);
      set have;
      by no code_2 date;
     If cd =: &lt;STRONG&gt;“X”&lt;/STRONG&gt; then flag=1;
   end;
   do until(last.date);
     set have;
     by no code_2 date;
     If flag then continue;
     output;
  end;
  flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 17:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919979#M362341</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-12T17:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Compare the character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919980#M362342</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, you are correct. Thank you for pointing that out. As is, this will surely cause issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me see if I can still amend it.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 17:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-the-character-values/m-p/919980#M362342</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-12T17:52:42Z</dc:date>
    </item>
  </channel>
</rss>

