Announcement

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

  • How to get the first 3 digit of a variable ?

    I have a variable name "WCO7023" (character type) receiving 3 types of results: 4-digit number, 3-digit number, and NA

    For example

    4412
    4564
    334
    NA
    7677

    What I want is to get the first 3 digit as below

    441
    456
    334
    .
    767

    Could you please let me know how to make it? I think of generate a new variable named "SIC3" which is numeric type but I am not sure how to make it.

    Warm regards.
    Last edited by Phuc Nguyen; 06 Dec 2021, 00:38.

  • #2
    Assuming WCO7023 is a string variable,

    Code:
    generate SIC3 = real(substr(WCO7023, 1, 3))
    should do.

    Comment


    • #3
      Originally posted by daniel klein View Post
      Assuming WCO7023 is a string variable,

      Code:
      generate SIC3 = real(substr(WCO7023, 1, 3))
      should do.
      Thanks daniel klein , it worked

      Comment

      Working...
      X