Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving a character in a string

    Hi all,

    Code:
    input str12 onetSocCode
    "29-1051.00"
    "29-1051.00"
    "291-051.00"
    "291-041.00"
    "29-1051.00"
    In the data above, I would like to have the "-" always in third position, after the second number, not after the third.

    How can I do this in a systematic manner for the whole variable?

    Many thanks!

  • #2

    Code:
    replace onetSocCode = subinstr(onetSocCode, "1-", "-1", 1) if substr(onetSocCode, 3, 2) == "1-"
    should work for your data example. Indeed, it's possible that the if qualifier isn't needed.
    Last edited by Nick Cox; 30 Jan 2024, 05:38.

    Comment


    • #3
      Worked perfectly, thanks!

      Comment


      • #4
        Please note key edit to #2.

        Comment

        Working...
        X