Announcement

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

  • arrays stata

    Hello, good afternoon, I have a database with a variable with this format {\pr":"8","pc":"3-5","pe":"5\ "} and I need to convert it into three example variables:
    pr pc pe
    8 3-5 5

    Thank you very much best regards

  • #2
    Provide a data example using dataex.

    Code:
    dataex in 1/5

    Comment


    • #3
      Hi Andres, thanks for your time. I attach the code. Kind regards.

      ----------------------- copy starting from the next line -----------------------
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int id str32(uid patient_id) str10 date_visit str4 test_data str49(value_p value_m) str48 value_r str7 source str10 source_date int user
      44 "060c3c4ec5f31caab99a992a6e4a548b" "1ed82928a7a000cc43bad1d33870313c" "2022-08-04" "NULL" "NULL"                                                `"{\"value\":\"8\",\"pc\":\"3-5\",\"pe\":\"5\"}"' "NULL" "eCemcat" "2022-08-04" 43
      47 "f721202b71592ae877457e8f052a9a18" "f274ce0a7fd7b635417b1fc592427fa4" "2022-10-04" "NULL" `"{\"value\":\"15\",\"pc\":\"41-59\",\"pe\":\"10\"}"' "NULL"                                            "NULL" "eCemcat" "2022-10-04" 43
      48 "e25588821feff011320d4b7af9d47ec8" "87dbd27e5c46ce9254aafb95eeb3f9d6" "2022-11-24" "NULL" "NULL"                                                "NULL"                                            "NULL" "eCemcat" "2022-11-24" 43
      49 "de035a44cb7dd72003912c47ef746cf3" "87dbd27e5c46ce9254aafb95eeb3f9d6" "2022-11-30" "NULL" `"{\"value\":\"12\",\"pc\":\"6-10\",\"pe\":\"6\"}"'   "NULL"                                            "NULL" "eCemcat" "2022-11-30" 43
      50 "b9d2b2ca1a07403b36fc5b085f0e650f" "87dbd27e5c46ce9254aafb95eeb3f9d6" "2022-12-02" "NULL" "NULL"                                                `"{\"value\":\"2\",\"pc\":\"< 1\",\"pe\":\"2\"}"' "NULL" "eCemcat" "2022-12-02"  1
      end
      ------------------ copy up to and including the previous line ------------------

      Comment


      • #4
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input int id str32(uid patient_id) str10 date_visit str4 test_data str49(value_p value_m) str48 value_r str7 source str10 source_date int user
        44 "060c3c4ec5f31caab99a992a6e4a548b" "1ed82928a7a000cc43bad1d33870313c" "2022-08-04" "NULL" "NULL"                                                `"{\"value\":\"8\",\"pc\":\"3-5\",\"pe\":\"5\"}"' "NULL" "eCemcat" "2022-08-04" 43
        47 "f721202b71592ae877457e8f052a9a18" "f274ce0a7fd7b635417b1fc592427fa4" "2022-10-04" "NULL" `"{\"value\":\"15\",\"pc\":\"41-59\",\"pe\":\"10\"}"' "NULL"                                            "NULL" "eCemcat" "2022-10-04" 43
        48 "e25588821feff011320d4b7af9d47ec8" "87dbd27e5c46ce9254aafb95eeb3f9d6" "2022-11-24" "NULL" "NULL"                                                "NULL"                                            "NULL" "eCemcat" "2022-11-24" 43
        49 "de035a44cb7dd72003912c47ef746cf3" "87dbd27e5c46ce9254aafb95eeb3f9d6" "2022-11-30" "NULL" `"{\"value\":\"12\",\"pc\":\"6-10\",\"pe\":\"6\"}"'   "NULL"                                            "NULL" "eCemcat" "2022-11-30" 43
        50 "b9d2b2ca1a07403b36fc5b085f0e650f" "87dbd27e5c46ce9254aafb95eeb3f9d6" "2022-12-02" "NULL" "NULL"                                                `"{\"value\":\"2\",\"pc\":\"< 1\",\"pe\":\"2\"}"' "NULL" "eCemcat" "2022-12-02"  1
        end
        
        gen tosplit= ustrregexra(value_p, "[^\d-,]", "")
        split tosplit, gen(wanted) p(,)
        Res.:

        Code:
        . l value_p wanted*
        
             +---------------------------------------------------------------------------------+
             |                                           value_p   wanted1   wanted2   wanted3 |
             |---------------------------------------------------------------------------------|
          1. |                                              NULL                               |
          2. | {\"value\":\"15\",\"pc\":\"41-59\",\"pe\":\"10\"}        15     41-59        10 |
          3. |                                              NULL                               |
          4. |   {\"value\":\"12\",\"pc\":\"6-10\",\"pe\":\"6\"}        12      6-10         6 |
          5. |                                              NULL                               |
             +---------------------------------------------------------------------------------+

        Comment


        • #5
          Thank you very much for the help, it is spectacular.
          Kind regards

          Comment

          Working...
          X