<?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: subsring on a variable length field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617974#M181192</link>
    <description>&lt;P&gt;If all you want to do is remove (all) 0s, you can use TRANWRD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newString = tranwrd(dataelement,'0','');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;that will replace 'A015478' with 'A 15478'.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jan 2020 00:17:09 GMT</pubDate>
    <dc:creator>JeffMaggio</dc:creator>
    <dc:date>2020-01-17T00:17:09Z</dc:date>
    <item>
      <title>subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617969#M181188</link>
      <description>&lt;P&gt;Hi guys -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a Data element A015478&lt;/P&gt;
&lt;P&gt;I need to remove the zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i figured i can do&amp;nbsp;&lt;BR /&gt;(SUBSTRN(dataelement,1,1)) to get the A separate.&lt;/P&gt;
&lt;P&gt;(SUBSTRN(dataelement,3,5)) to get the numbers after the zero&lt;/P&gt;
&lt;P&gt;and concatenate them together.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(SUBSTRN(dataelement,1,1)) ||(SUBSTRN(dataelement,3,5))&amp;nbsp; hoping to get A15478&lt;BR /&gt;&lt;BR /&gt;the issue is that sometimes the data in that field is A01457 sometimes A02457896&amp;nbsp; or even A0210501 (a second zero that i need to keep) -- the length of the number portion after the zero is variable.&lt;BR /&gt;&lt;BR /&gt;i was thinking i could use a length statement in that last part... and thinking i may need a put or input to change the type --- but keep getting errors - can anyone help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What i tried, and the resulting error:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;(SUBSTRN(dataelement,1,1))|| (SUBSTRN(dataelement,3,(length((dataelement)-2))))&lt;BR /&gt;ERROR: Expression using subtraction (-) requires numeric types.&lt;BR /&gt;ERROR: Function LENGTH requires a character expression as argument 1.&lt;BR /&gt;ERROR: Function SUBSTRN requires a numeric expression as argument 3.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 23:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617969#M181188</guid>
      <dc:creator>SVoldrich</dc:creator>
      <dc:date>2020-01-16T23:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617973#M181191</link>
      <description>&lt;P&gt;i'm getting closer:&lt;BR /&gt;(SUBSTRN(dataelem,1,1))|| (SUBSTRN(dataelem,3,(length(dataelem)-2)))&lt;BR /&gt;&lt;BR /&gt;but when I add it to my where clause, i'm getting 2 rows...&lt;/P&gt;
&lt;P&gt;when dataelem is not null and dataelem like 'A%' and ((SUBSTRN(dataelem,1,1))|| (SUBSTRN(dataelem,3,(length(dataelem)-2))))=otherdataelem then otherdataelem&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else 'still reviewing'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get one row with otherdataelem and a second row with still reviewing&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2020 23:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617973#M181191</guid>
      <dc:creator>SVoldrich</dc:creator>
      <dc:date>2020-01-16T23:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617974#M181192</link>
      <description>&lt;P&gt;If all you want to do is remove (all) 0s, you can use TRANWRD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newString = tranwrd(dataelement,'0','');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;that will replace 'A015478' with 'A 15478'.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2020 00:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617974#M181192</guid>
      <dc:creator>JeffMaggio</dc:creator>
      <dc:date>2020-01-17T00:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617976#M181194</link>
      <description>&lt;P&gt;ok, that statement works.&amp;nbsp;&lt;BR /&gt;my problem was the other table i was linking to had 2 rows of data one that matched my new concatenated data element, and one that didn't.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;saving this for reference for anyone else stuck!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2020 00:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617976#M181194</guid>
      <dc:creator>SVoldrich</dc:creator>
      <dc:date>2020-01-17T00:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617979#M181197</link>
      <description>&lt;P&gt;Sorry, it took a bit for SAS to boot up for me to test that. I edited my above post to reflect the actual behavior.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TRANWRD will replace using a space for the empty string in the third argument.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to remove the space, you can use TRANSTRN and TRIMN like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newString = transtrn(dataelement,'0',trimn(''));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jan 2020 00:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617979#M181197</guid>
      <dc:creator>JeffMaggio</dc:creator>
      <dc:date>2020-01-17T00:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617981#M181199</link>
      <description>TRANWRD and replacement won't work because of this requirement:&lt;BR /&gt;&lt;BR /&gt;or even A0210501 (a second zero that i need to keep) -- the length of the number portion after the zero is variable.&lt;BR /&gt;&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1024"&gt;@SVoldrich&lt;/a&gt;, you'll need to show more clearly what you have and what you expect. For the example above what would you want? Is it only the second 0 you want to ever replace? If so, that's quite trivial but its hard to tell from your post.</description>
      <pubDate>Fri, 17 Jan 2020 00:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617981#M181199</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-17T00:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617986#M181204</link>
      <description>&lt;P&gt;Whoops I didn't see that sometimes there are 0s to be kept. I agree that the solution is trivial if it is only the second position 0 that needs to be removed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1024"&gt;@SVoldrich&lt;/a&gt;the substr and substrn functiona do not need the third (final) argument for the length to keep. If that is the case, you can use your original idea without the third argument in the second part:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(SUBSTRN(dataelement,1,1)) ||(SUBSTRN(dataelement,3))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jan 2020 01:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617986#M181204</guid>
      <dc:creator>JeffMaggio</dc:creator>
      <dc:date>2020-01-17T01:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617990#M181208</link>
      <description>There's also the SUBSTR() right of operation that could likely be employed but it depends on the OP's exact requirements.</description>
      <pubDate>Fri, 17 Jan 2020 02:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/617990#M181208</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-17T02:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: subsring on a variable length field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/618000#M181214</link>
      <description>&lt;P&gt;How consist is the data? How many digits could there be?&amp;nbsp; Why not convert the digits to a number and then back to digits?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cats(char(dataelement,1),input(substr(dataelement,2),32.))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2020 04:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsring-on-a-variable-length-field/m-p/618000#M181214</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-17T04:34:21Z</dc:date>
    </item>
  </channel>
</rss>

