<?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: Need to replace last character in a variable with a numeric number in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71775#M20740</link>
    <description>The error occurs at the ")" parentheses before the seven</description>
    <pubDate>Wed, 16 Sep 2009 14:09:17 GMT</pubDate>
    <dc:creator>LAtwood</dc:creator>
    <dc:date>2009-09-16T14:09:17Z</dc:date>
    <item>
      <title>Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71771#M20736</link>
      <description>I have a character variable titled "load_lbs" and it is formatted as an example like this: "079460K"&lt;BR /&gt;
&lt;BR /&gt;
The letter will always fall in 7th (or last position).&lt;BR /&gt;
&lt;BR /&gt;
I need to replace the last character value with a number and it needs to be a numeric variable.&lt;BR /&gt;
&lt;BR /&gt;
K = -1, L=-2, A=1, etc.&lt;BR /&gt;
For example the K needs to be replaced with the number 1 and the number needs to be negative. (Ebcdic)&lt;BR /&gt;
&lt;BR /&gt;
This is already a SAS dataset that needs to be modified&lt;BR /&gt;
&lt;BR /&gt;
Any help with this would be appreciated.</description>
      <pubDate>Wed, 16 Sep 2009 13:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71771#M20736</guid>
      <dc:creator>LAtwood</dc:creator>
      <dc:date>2009-09-16T13:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71772#M20737</link>
      <description>One approach is to use the TRANWRD function to perform the replacement and also use the FIND function to locate the character match, using argument three as -99 to start from the end.  Two ARRAYs of candidate source and replacement character strings (one or more than one) would be declared in your program and you would use a DO / END code paragraph to loop through the list of character-strings for replacement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Sep 2009 13:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71772#M20737</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-16T13:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71773#M20738</link>
      <description>So, does the result for &lt;BR /&gt;
079460K&lt;BR /&gt;
look like&lt;BR /&gt;
079460-1&lt;BR /&gt;
or&lt;BR /&gt;
-0794601&lt;BR /&gt;
&lt;BR /&gt;
Either way, you can do it with a SELECT statement with a SUBSTR to pull of the last letter and the various WHEN statements to do the assignments, again using SUBSTR.&lt;BR /&gt;
&lt;BR /&gt;
If you do the replacement in place, the result will still be a character string containing numerals.  To get a new variable that is numeric, you need to wrap the SUBSTR with an INPUT function.&lt;BR /&gt;
&lt;BR /&gt;
The SELECT would look like&lt;BR /&gt;
SELECT (SUBSTR(load_lbs,7,1));&lt;BR /&gt;
&lt;BR /&gt;
For 079460K and the a numeric output, WHEN would be&lt;BR /&gt;
&lt;BR /&gt;
WHEN ('K') NewLoadLbs= - INPUT(substr(load_lbs,1,6)||'1'),7.);</description>
      <pubDate>Wed, 16 Sep 2009 13:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71773#M20738</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2009-09-16T13:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71774#M20739</link>
      <description>Thanks for you help so far, but&lt;BR /&gt;
I have multiple when statements:&lt;BR /&gt;
and I get the following error when I try this:&lt;BR /&gt;
when ('{') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'0'),7.),&lt;BR /&gt;
                                                                                           -&lt;BR /&gt;
                                                                                          388&lt;BR /&gt;
                                                                                          76&lt;BR /&gt;
                                                                                            -&lt;BR /&gt;
                                                                                            200&lt;BR /&gt;
ERROR 388-185: Expecting an arithmetic operator.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 200-322: The symbol is not recognized and will be ignored.</description>
      <pubDate>Wed, 16 Sep 2009 14:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71774#M20739</guid>
      <dc:creator>LAtwood</dc:creator>
      <dc:date>2009-09-16T14:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71775#M20740</link>
      <description>The error occurs at the ")" parentheses before the seven</description>
      <pubDate>Wed, 16 Sep 2009 14:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71775#M20740</guid>
      <dc:creator>LAtwood</dc:creator>
      <dc:date>2009-09-16T14:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71776#M20741</link>
      <description>With SAS, it's important to share more than just the (apparent) failing code line -- share the ENTIRE DATA step code for most accurate diagnosis and feedback.&lt;BR /&gt;
&lt;BR /&gt;
And, for self-diagnosis, try commenting out parts of the DATA step code to attempt to isolate the problem root cause -- also add PUTLOG commands and such to help with your own code diagnosis.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Sep 2009 14:20:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71776#M20741</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-16T14:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71777#M20742</link>
      <description>Here is the line of code:&lt;BR /&gt;
 data FD020_0148_LKUP ;&lt;BR /&gt;
        set FD020_0148_LKUP ;&lt;BR /&gt;
		select (substr(wgh_reg_lbs,7,1));&lt;BR /&gt;
		when ('{') new_wgh_reg_lbs= substr(wgh_reg_lbs,1,6)||'0',8.),&lt;BR /&gt;
		when ('A') new_wgh_reg_lbs= substr(wgh_reg_lbs,1,6)||'1',8.);&lt;BR /&gt;
		/*when ('B') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'2'),7.),&lt;BR /&gt;
		when ('C') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'3'),7.),&lt;BR /&gt;
		when ('D') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'4'),7.),&lt;BR /&gt;
		when ('E') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'5'),7.),&lt;BR /&gt;
		when ('F') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'6'),7.),&lt;BR /&gt;
		when ('G') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'7'),7.),&lt;BR /&gt;
		when ('H') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'8'),7.),&lt;BR /&gt;
		when ('I') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'9'),7.),&lt;BR /&gt;
		when ('}') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'0'),7.),&lt;BR /&gt;
		when ('J') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'1'),7.),&lt;BR /&gt;
		when ('K') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'2'),7.),&lt;BR /&gt;
		when ('L') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'3'),7.),&lt;BR /&gt;
		when ('M') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'4'),7.),&lt;BR /&gt;
		when ('N') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'5'),7.),&lt;BR /&gt;
		when ('O') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'6'),7.),&lt;BR /&gt;
		when ('P') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'7'),7.),&lt;BR /&gt;
		when ('Q') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'8'),7.),&lt;BR /&gt;
		when ('R') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'9'),7.);*/&lt;BR /&gt;
		end;</description>
      <pubDate>Wed, 16 Sep 2009 14:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71777#M20742</guid>
      <dc:creator>LAtwood</dc:creator>
      <dc:date>2009-09-16T14:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71778#M20743</link>
      <description>Check your assignment statements in the first WHEN stmt as compared to those that following the "A" WHEN test - notice any difference?&lt;BR /&gt;
&lt;BR /&gt;
BTW, I tested your code by pasting it into a SAS window and converted the DATA and SET statements to be:&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
retain wgh_reg_lbs '222222A';&lt;BR /&gt;
select (substr(wgh_reg_lbs,7,1));&lt;BR /&gt;
&lt;BR /&gt;
After adding the statements below at the end- the code was self-contained and could be tested independent of all other processing -- which helped reveal the problem cause - your INPUT function is missing in the first WHEN:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG _ALL_;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Some thoughts for future self-diagnosis and program testing.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Sep 2009 14:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71778#M20743</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-16T14:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71779#M20744</link>
      <description>Scott&lt;BR /&gt;
I apologize.  I was trying different options when the first two lines of code to try to de-bug the error.  Here is what the code looks like and I am still getting the same error:&lt;BR /&gt;
*------------------------------------------------------transform data--;&lt;BR /&gt;
    data FD020_0148_LKUP ;&lt;BR /&gt;
        set FD020_0148_LKUP ;&lt;BR /&gt;
		select (substr(wgh_reg_lbs,7,1));&lt;BR /&gt;
		when ('{') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'0'),8.),&lt;BR /&gt;
	/*	when ('A') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'1'),8.),&lt;BR /&gt;
		when ('B') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'2'),7.),&lt;BR /&gt;
		when ('C') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'3'),7.),&lt;BR /&gt;
		when ('D') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'4'),7.),&lt;BR /&gt;
		when ('E') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'5'),7.),&lt;BR /&gt;
		when ('F') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'6'),7.),&lt;BR /&gt;
		when ('G') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'7'),7.),&lt;BR /&gt;
		when ('H') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'8'),7.),&lt;BR /&gt;
		when ('I') new_wgh_reg_lbs= INPUT(substr(wgh_reg_lbs,1,6)||'9'),7.),&lt;BR /&gt;
		when ('}') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'0'),7.),&lt;BR /&gt;
		when ('J') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'1'),7.),&lt;BR /&gt;
		when ('K') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'2'),7.),&lt;BR /&gt;
		when ('L') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'3'),7.),&lt;BR /&gt;
		when ('M') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'4'),7.),&lt;BR /&gt;
		when ('N') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'5'),7.),&lt;BR /&gt;
		when ('O') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'6'),7.),&lt;BR /&gt;
		when ('P') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'7'),7.),&lt;BR /&gt;
		when ('Q') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'8'),7.),&lt;BR /&gt;
		when ('R') new_wgh_reg_lbs= -INPUT(substr(wgh_reg_lbs,1,6)||'9'),7.);*/&lt;BR /&gt;
		end;&lt;BR /&gt;
		date     =inputn(dt,'yymmdd.') ;&lt;BR /&gt;
        drop dt;&lt;BR /&gt;
		drop load_mis_lbs;&lt;BR /&gt;
		drop load_skids;&lt;BR /&gt;
		drop load_reg_lbs;&lt;BR /&gt;
		drop wgh_mis_lbs;&lt;BR /&gt;
		drop other_lbs;&lt;BR /&gt;
		drop wgh_reg_lbs;&lt;BR /&gt;
    run ;</description>
      <pubDate>Wed, 16 Sep 2009 14:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71779#M20744</guid>
      <dc:creator>LAtwood</dc:creator>
      <dc:date>2009-09-16T14:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71780#M20745</link>
      <description>Scott,&lt;BR /&gt;
&lt;BR /&gt;
I have found the issue.&lt;BR /&gt;
data FD020_0148_LKUP ;&lt;BR /&gt;
        set FD020_0148_LKUP ;&lt;BR /&gt;
		select (substr(wgh_reg_lbs,7,1));&lt;BR /&gt;
		when ('{') new_wgh_reg_lbs= INPUT((substr(wgh_reg_lbs,1,6)||'0'),8.) ;&lt;BR /&gt;
&lt;BR /&gt;
A parantheses needed to be added before the substr statement in the when clause.  I was also missing the otherwise;&lt;BR /&gt;
&lt;BR /&gt;
thanks for your help</description>
      <pubDate>Wed, 16 Sep 2009 14:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71780#M20745</guid>
      <dc:creator>LAtwood</dc:creator>
      <dc:date>2009-09-16T14:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71781#M20746</link>
      <description>Those parantheses bracketing the SUBSTR  function and concatenation have no code/processing impact - though they may be meaningful for reading/viewing the code.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Sep 2009 15:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71781#M20746</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-16T15:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71782#M20747</link>
      <description>Also, you may want to code an OTHERWISE statement, in case your SELECT/WHEN/END does not have a suitable match to fulfill one of the WHEN statements listed.  Also, I don't believe that your INPUTN function use is appropriate.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Sep 2009 15:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71782#M20747</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-16T15:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71783#M20748</link>
      <description>Thanks, i meant for the inputn to be input.</description>
      <pubDate>Wed, 16 Sep 2009 15:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71783#M20748</guid>
      <dc:creator>LAtwood</dc:creator>
      <dc:date>2009-09-16T15:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need to replace last character in a variable with a numeric number</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71784#M20749</link>
      <description>And for your assignment statement, the quote marks around the INFORMAT will generate a SAS error.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Sep 2009 15:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-to-replace-last-character-in-a-variable-with-a-numeric/m-p/71784#M20749</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-16T15:35:05Z</dc:date>
    </item>
  </channel>
</rss>

