Announcement

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

  • Adding 0s before a numeric variable

    Hello,

    I am working with drug NDC codes of claims data. Initially, the format for this variable could only accomodate 9 numbers, thus I changed it to %12g. Now, I am able to see the codes but the leading 0s have disappered. for eg: 005447282 is seen as 5447282. Is there a way I can generate another variable with required numbers of leading 0s for each ndcnum (every ndcnum has varying numbers of deficient leading 0s) and then merge these two variables in the same dataset? Note: I imported this dataset from SAS

  • #2
    I don't know what "NDC" stands for but if this is an ID of some kind, it should be a string variable, not a numeric one; if you really need it as numeric, you can use the format command:
    Code:
     right-justified with leading zeros
                  %0#.#f          fixed                    %09.2f
    the above is quoted from "help format"

    if you want this as a string, see
    Code:
    h tostring

    Comment


    • #3
      Thanks so much!
      I was able to do this by converting it into string
      the code:
      gen ndcnum_str = string(ndcnum, "%011.0f")

      Comment

      Working...
      X