<?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: compress or left trim in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248811#M56476</link>
    <description>great! thanks again!</description>
    <pubDate>Tue, 09 Feb 2016 05:07:45 GMT</pubDate>
    <dc:creator>archibald</dc:creator>
    <dc:date>2016-02-09T05:07:45Z</dc:date>
    <item>
      <title>compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248604#M56450</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a character variable&amp;nbsp;ID is as follows :&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;1002-004567-UC&lt;/P&gt;&lt;P&gt;1002-000062-UC&lt;/P&gt;&lt;P&gt;1002-239874-UC&lt;/P&gt;&lt;P&gt;&amp;nbsp;I would like&amp;nbsp;to transform the &amp;nbsp;ID&amp;nbsp;variable such as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;4567&lt;/P&gt;&lt;P&gt;62&lt;/P&gt;&lt;P&gt;239874&lt;/P&gt;&lt;P&gt;What would be the appropriate syntax to use?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 02:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248604#M56450</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-02-08T02:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248607#M56451</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input ID $20.;&lt;BR /&gt;datalines;&lt;BR /&gt;1002-004567-UC&lt;BR /&gt;1002-000062-UC&lt;BR /&gt;1002-239874-UC&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data want(drop=id rename=id1=id);&lt;BR /&gt;set have;&lt;BR /&gt;ID1=input(scan(ID,2),8.);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 02:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248607#M56451</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-02-08T02:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248610#M56452</link>
      <description>&lt;P&gt;Do you want the variable to be character or numeric?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution above generates a numeric ID. &amp;nbsp;In general ID's should be character to avoid accidental mathematical issues and precision issues in merging.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SCAN() isolates the middle term&lt;/P&gt;
&lt;P&gt;INPUT() converts to a number, so it removes the leading zero's&lt;/P&gt;
&lt;P&gt;PUT() converts it back to a character, -l, left aligns the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ID_VAR = put(input(scan(var, 2, "-"), 8.), 8. -l);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Feb 2016 03:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248610#M56452</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-08T03:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248618#M56453</link>
      <description>&lt;P&gt;You could also use pattern matching&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ids;
input idStr :$16.;
datalines;
1002-004567-UC
1002-000062-UC
1002-239874-UC
;

data want;
set ids;
id = prxchange("s/.*-0*([1-9]\d*)-.*/\1/o", 1, idStr);
run;

proc print data=want noobs; run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The pattern reads: &lt;EM&gt;Find any string, followed by a dash, followed by any number of zeros, ( &lt;STRONG&gt;followed by a digit between 1 and 9, followed by any number of digits&lt;/STRONG&gt; ), followed by a dash, followed by anything. Keep the string part matched within the parentheses.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 03:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248618#M56453</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-08T03:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248764#M56468</link>
      <description>PGStats,&lt;BR /&gt;This works great! Thanks!!&lt;BR /&gt;Also say the ID variable was as follows:&lt;BR /&gt;1002-004567UC&lt;BR /&gt;1002-000062UC&lt;BR /&gt;1002-239874UC&lt;BR /&gt;which part of the code should I modify to get the same result&lt;BR /&gt;ID&lt;BR /&gt;4567&lt;BR /&gt;62&lt;BR /&gt;239874&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Feb 2016 22:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248764#M56468</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-02-08T22:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248765#M56469</link>
      <description>sat_sas,&lt;BR /&gt;the code provided does not work for me. I got the following error message :Invalid argument to function INPUT&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Feb 2016 23:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248765#M56469</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-02-08T23:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248766#M56470</link>
      <description>Thanks Reeza for your reply.&lt;BR /&gt;I am not sure this is on my end, but I was not successful using this code. I got an error message Invalid argument to function INPUT&lt;BR /&gt;perhaps I am missing something...&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Feb 2016 23:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248766#M56470</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-02-08T23:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248767#M56471</link>
      <description>&lt;P&gt;Replace the pattern with&amp;nbsp;"s/.*-0*([1-9]\d*)\D.*/\1/o"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would actually work also with your original question. It says that the number field ends when a non number character is found.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 23:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248767#M56471</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-08T23:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248768#M56472</link>
      <description>&lt;P&gt;I guess you could just as well use&amp;nbsp;"s/.*-0*([1-9]\d*).*/\1/o" which would work even if the number goes to the end of the string.&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 23:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248768#M56472</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-08T23:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: compress or left trim</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248811#M56476</link>
      <description>great! thanks again!</description>
      <pubDate>Tue, 09 Feb 2016 05:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compress-or-left-trim/m-p/248811#M56476</guid>
      <dc:creator>archibald</dc:creator>
      <dc:date>2016-02-09T05:07:45Z</dc:date>
    </item>
  </channel>
</rss>

