<?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: Removing specific characters from the beginning and end of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58689#M12744</link>
    <description>Hi:&lt;BR /&gt;
  In file A the IDs must be character strings. What about file B? Are the IDs numeric or character variables???&lt;BR /&gt;
 &lt;BR /&gt;
  If the data is exactly as you describe (that the IDs in file A always start with a 'p' or a 'p-'), then I'd probably recommend that you investigate the SCAN function. What remains to be determined is whether you will be doing a character to character comparison between the IDs in file A and file B or whether you will be doing a numeric to numeric comparison between the IDs.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Tue, 04 Jan 2011 23:17:55 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2011-01-04T23:17:55Z</dc:date>
    <item>
      <title>Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58688#M12743</link>
      <description>I have  IDs in file A as follows:&lt;BR /&gt;
p704987-1&lt;BR /&gt;
p789094-22&lt;BR /&gt;
p-3455-3&lt;BR /&gt;
&lt;BR /&gt;
In file B I have IDs as follows:&lt;BR /&gt;
704987&lt;BR /&gt;
789094&lt;BR /&gt;
3455&lt;BR /&gt;
&lt;BR /&gt;
They are same ID, but in file A, a letter has been added to the beginning as well as a (-) and number following that are not needed.&lt;BR /&gt;
&lt;BR /&gt;
I need to remove the p at the beginning of the ID variable in file A and remove the (-) and any following numbers after the (-) for ID variable in file A as well so I can merge the data from file A with file B using the ID variable from both files, but I cannot seem to figure out the right code. Any help is appreciated. Thank you.

Message was edited by: JHale</description>
      <pubDate>Tue, 04 Jan 2011 22:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58688#M12743</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-04T22:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58689#M12744</link>
      <description>Hi:&lt;BR /&gt;
  In file A the IDs must be character strings. What about file B? Are the IDs numeric or character variables???&lt;BR /&gt;
 &lt;BR /&gt;
  If the data is exactly as you describe (that the IDs in file A always start with a 'p' or a 'p-'), then I'd probably recommend that you investigate the SCAN function. What remains to be determined is whether you will be doing a character to character comparison between the IDs in file A and file B or whether you will be doing a numeric to numeric comparison between the IDs.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 04 Jan 2011 23:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58689#M12744</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-01-04T23:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58690#M12745</link>
      <description>Regular expressions would probably be the easiest way to solve the problem, but you could also probably do it with something like:&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  id=substr(id,1,findc(id,'-',-length(id))-1);&lt;BR /&gt;
  id=substr(id,findc(id,,'d'));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 05 Jan 2011 00:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58690#M12745</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-01-05T00:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58691#M12746</link>
      <description>Hi.&lt;BR /&gt;
Just as Cynthia said.&lt;BR /&gt;
Use Function scan() would be more simpler.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
 input id : $20.;&lt;BR /&gt;
 id=scan(id,-2,'-pP');&lt;BR /&gt;
 put id=;&lt;BR /&gt;
cards;&lt;BR /&gt;
p704987-1&lt;BR /&gt;
p789094-22&lt;BR /&gt;
p-3455-3&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 05 Jan 2011 02:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58691#M12746</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-05T02:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58692#M12747</link>
      <description>As long as the prefix is always a 'p' I totally agree.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Wed, 05 Jan 2011 03:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58692#M12747</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-01-05T03:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58693#M12748</link>
      <description>Hi:&lt;BR /&gt;
  Actually, the prefix can be either - or p or p- or -p or not there at all -- SCAN ignores leading delimiters so this data:&lt;BR /&gt;
[pre]&lt;BR /&gt;
p704987-1&lt;BR /&gt;
p789094-22&lt;BR /&gt;
p-3455-3&lt;BR /&gt;
-1234-p44&lt;BR /&gt;
34567p-55&lt;BR /&gt;
-p98765-66&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                   &lt;BR /&gt;
Can all use this program:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data char_id;&lt;BR /&gt;
  length char_id $12;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input char_id $;&lt;BR /&gt;
  new_char_id = scan(char_id,1,'p-');&lt;BR /&gt;
  new_num_id = input(new_char_id,best8.);&lt;BR /&gt;
  put _n_= char_id= new_char_id= new_num_id= ; &lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
p704987-1&lt;BR /&gt;
p789094-22&lt;BR /&gt;
p-3455-3&lt;BR /&gt;
-1234-p44&lt;BR /&gt;
34567p-55&lt;BR /&gt;
-p98765-66&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
              &lt;BR /&gt;
With these results in the log:&lt;BR /&gt;
[pre]&lt;BR /&gt;
_N_=1 char_id=p704987-1 new_char_id=704987 new_num_id=704987&lt;BR /&gt;
_N_=2 char_id=p789094-22 new_char_id=789094 new_num_id=789094&lt;BR /&gt;
_N_=3 char_id=p-3455-3 new_char_id=3455 new_num_id=3455&lt;BR /&gt;
_N_=4 char_id=-1234-p44 new_char_id=1234 new_num_id=1234&lt;BR /&gt;
_N_=5 char_id=34567p-55 new_char_id=34567 new_num_id=34567&lt;BR /&gt;
_N_=6 char_id=-p98765-66 new_char_id=98765 new_num_id=98765&lt;BR /&gt;
[/pre]&lt;BR /&gt;
          &lt;BR /&gt;
SCAN is pretty cool for a low-tech, non-PRX function.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 05 Jan 2011 06:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58693#M12748</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-01-05T06:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58694#M12749</link>
      <description>Hi.&lt;BR /&gt;
I scan it from right not left,So as long as the right character is to looks like '-23' '-p23',that will be OK.&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 05 Jan 2011 07:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58694#M12749</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-01-05T07:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58695#M12750</link>
      <description>Thank you so much! This worked perfectly.</description>
      <pubDate>Wed, 05 Jan 2011 14:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58695#M12750</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-05T14:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58696#M12751</link>
      <description>Thank you to everyone for your advice and help. Much appreciation.</description>
      <pubDate>Wed, 05 Jan 2011 14:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58696#M12751</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-05T14:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Removing specific characters from the beginning and end of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58697#M12752</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
If your string begins with other letters than p maybe this solution will fit:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
input x $40.;&lt;BR /&gt;
y=compress(substr(x,1,find(trim(x),'-',-length(trim(x)))), ,'kd');&lt;BR /&gt;
datalines;&lt;BR /&gt;
p704987-1&lt;BR /&gt;
p789094-22&lt;BR /&gt;
p-03455-3&lt;BR /&gt;
-1234-p44&lt;BR /&gt;
34567p-55&lt;BR /&gt;
-p98765-66&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Thu, 06 Jan 2011 11:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-specific-characters-from-the-beginning-and-end-of-a/m-p/58697#M12752</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-06T11:46:19Z</dc:date>
    </item>
  </channel>
</rss>

