Announcement

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

  • help with string variable comprising multiple lines

    Hi Statalist,

    After importing from Excel (-import excel-; .xlsx), I have some string variable values that comprise multiple lines.

    For example:
    Code:
    . di var1[108]
    This 
        is 
       one 
       string variable
    .
    Is there any way to trim this to one line? Or is that something that needs to be done in Excel before I import?

    Thanks in advance,

    Reese
    v 14.2

  • #2
    So it appears that this variable contains some character that displays in such a way as to cause a line break. If this is not Unicode data, the most likely culprit is a line-feed, which is ASCII character 10. If that's it:

    Code:
    replace var1 = subinstr(var1, "`=char(10)'", " ", .)
    That will replace all of those characters with ordinary spaces. If you then have double spaces between words that you want to get rid of, follow up with
    Code:
    replace var1 = itrim(var1)
    Now, if ASCII character 10 isn't the culprit, you need to find out what is. For that purpose, I recommend you install Robert Picard's -chartab- program, -ssc install chartab-. Run -chartab var1- and you will get a list of all the characters that occur in your variable, along with a description, and you will probably be able to figure out from the descriptions which one is causing the difficulty and then eliminate it along the lines shown above.

    Comment


    • #3
      Thanks Clyde! Good call--that's exactly what I was looking for!

      Comment

      Working...
      X