<?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: remove character value from string based on position in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804724#M316935</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
   input date_have $ 1-20;
   datalines;
00JAN2020
UNJAN2020
UNUNK2020
UNJUN2020
01JUN2020
;
run;

data want;
 set test;
want=prxchange('s/^UN|^00|UNK//i',-1,date_have);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Mar 2022 12:06:11 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-03-29T12:06:11Z</dc:date>
    <item>
      <title>remove character value from string based on position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804499#M316820</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have day or month is unknown and listed as UN and UNK respectively.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Dataset:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data TEST;
   input date_have $ 1-20;
   datalines;
00JAN2020
UNJAN2020
UNUNK2020
UNJUN2020
01JUN2020
;
run;

data CLEAN ;
   	set TEST;
  	C = 'UN'; *&amp;lt;- leading character(s) to be removed;
 	D = "UNK";
 	E = "00";
   	P1 = verify(date_have,C);
   
   	if P1 then date_want = substr(date_have, P1);    
         else date_want = '';
 
 	P1 = verify(date_want,D); 
   	if P1 then date_want = substr(date_want, P1);    
         else date_want = '';
 
 	P1 = verify(date_want,E); 
   	if P1 then date_want = substr(date_want, P1);    
         else date_want = '';
     if P1=2 then date_want = date_have;    
    drop c d e;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to remove 00 or UN or UNK. I do not want to remove UN from month JUN. By using my code, I am removing leading zero (0) from date&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above code is working but I am requesting to get something simple code for desire output.&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="dht115_0-1648474158690.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69873iC72D59B621F9C3D3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dht115_0-1648474158690.png" alt="dht115_0-1648474158690.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 13:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804499#M316820</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-03-28T13:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: remove character value from string based on position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804519#M316832</link>
      <description>&lt;P&gt;You can make use of the "=:" relation operator, and the TRNSTRN function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
   input date_have $ 1-20;
   datalines;
00JAN2020
UNJAN2020
UNUNK2020
UNJUN2020
01JUN2020
;
run;

data want;
  set test;
  if date_have =: 'UN' or date_have =: '00' then date_want=substr(date_have,3); 
  else  date_want=date_have;
  date_want=transtrn(date_want,'UNK','');
  put (_all_) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The '=:' operator compares only the initial characters.&amp;nbsp; The comparison will examine only as many characters as the shorter of the two comparison values.&amp;nbsp; So in the above, there is a check for leading "UN"&amp;nbsp; and leading "00".&amp;nbsp; &amp;nbsp;The TRANSTRN removes "UNK" from the value regardless of whether it is the leading character string, or an interior character string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note this assumes that your DATE_HAVE always leads with a day-of-month value, or "UN", or "00".&amp;nbsp; &amp;nbsp;I.e. none of your DATE_HAVE values start with "UNK"&amp;nbsp; (as in UNK2020) - although that could be trivially addressed.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 14:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804519#M316832</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-28T14:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: remove character value from string based on position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804724#M316935</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
   input date_have $ 1-20;
   datalines;
00JAN2020
UNJAN2020
UNUNK2020
UNJUN2020
01JUN2020
;
run;

data want;
 set test;
want=prxchange('s/^UN|^00|UNK//i',-1,date_have);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2022 12:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804724#M316935</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-29T12:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: remove character value from string based on position</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804893#M316996</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to compare partial date with actual date in sas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data TEST;
   input date_have $ 9. date_compare $ 9.;
   datalines;
00JAN2020 10NOV2020
UNJAN2020 05DEC2020
UNUNK2020 16DEC2019
UNJUN2020 14FEB2021
01JAN2020 01MAY2020
20JUN2020 01JAN2020
;
run;

DATA TEST1;
SET TEST;
/* DELETE 00, UN, UNK BY USING PRXCHANGE FUNCTION */
NEW_have=prxchange('s/^UN|^00|UNK//i',-1,date_have);

RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to compare new_have variable to date_compare variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;new_have &amp;lt;=date_compare&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;When I run above code, I need to remove Observation 3 and Observation 6.&lt;/P&gt;&lt;P&gt;Observation 3 - compare date is in 2019 and our original date is in 2020.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Observation 6 - compare date is in JAN2020 and our original date is in JUN2020.&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="dht115_1-1648588240148.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69935i7C479ED0A99613C5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dht115_1-1648588240148.png" alt="dht115_1-1648588240148.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 21:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-character-value-from-string-based-on-position/m-p/804893#M316996</guid>
      <dc:creator>dht115</dc:creator>
      <dc:date>2022-03-29T21:13:54Z</dc:date>
    </item>
  </channel>
</rss>

