Announcement

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

  • SAS labeled string

    One famous feature of Some Alternative Software that reaches really far beyond what Stata is capable of are labeled strings. I am working with a SAS data set that has say string variable SEX that has values "01" (yes, a string) with a label "Female" and value "02" (yes, a string) with a label "Male". How do I convert that into something more sensible? SAS PROC EXPORT creates a data set in which the impoverished Stata loses the labels.

    I am totally dazzled that destring that we all know and love does not exist in SAS, and people have to write bizarre 60-line macros to achieve that goal (https://communities.sas.com/servlet/..._Variables.pdf). Yet the solution outlined there does not retain the labeled strings.
    -- Stas Kolenikov || http://stas.kolenikov.name
    -- Principal Survey Scientist, Abt SRBI
    -- Opinions stated in this post are mine only


  • #2
    I've never used SAS. My one claim here is to have introduced "Some Alternative Software" to Stata users' meetings as the term of choice, although the scope for other people to devise the same feeble joke is infinite.

    But can you clone the labelled string variable in SAS, strip the clone of its labels and vice versa, and import both as strings?

    Comment


    • #3
      Stas,

      This Statlist post from 2010 suggests that there is no easy way to do what you are asking: http://www.stata.com/statalist/archive/2010-01/msg00624.html. The author suggests a method in SAS that sounds like what Nick suggested above and which parallels the SAS equivalent of destring that you linked to.

      Like Stata, SAS has value labels (called formats) that can be associated with one or more variables. Unlike Stata, these formats are not stored with the data set but are either defined locally or stored as a separate file (a format library). Accordingly, when converting from SAS to Stata there are generally two choices: lose the formats or lose the original values. The user-written usesas (available from SSC and referenced in the 2010 post) can convert SAS numeric formats to Stata value labels but cannot do the same with SAS character formats.

      Regards,
      Joe

      Comment


      • #4
        Does anybody know how StatTransfer handles SAS' labeled string variables when exporting to Stata?

        Comment


        • #5
          Clyde,

          I didn't even know that StatTransfer handled SAS formats until you asked the question (this feature is turned off by default). However, even if StatTransfer is set to read a value label from a format file, it apparently ignores character formats (not surprisingly since Stat doesn't support them).

          Regards,
          Joe

          Comment


          • #6
            Stas,

            Incidentally, the SAS-equivalent of destring that you refer to is not as complicated as it appears. The guts of it is one statement:

            Code:
            x=input(charx,best12.);
            The rest is error-checking and other housekeeping. I daresay that Stata's destring.ado is every bit as complicated looking.

            Also, doing what Nick suggested is relatively easy. If you have a character variable (say, x) with a character format (say, $x_f) you could do:

            Code:
            x_label=put(x,$x_f.);
            Then you would have a variable x_label which contains the label corresponding to the value of x. After that, I'm not sure what you would do; it depends on your objective.

            Regards,
            Joe

            Comment


            • #7
              Joe, Clyde, Nick, thank you for the pointers. I should've put (c) NJC on the unabbreviation mentioned in this thread.

              Resolution: I hard-coded five or so variables that I needed, and did not try to find a permanent soft-coded solution.
              -- Stas Kolenikov || http://stas.kolenikov.name
              -- Principal Survey Scientist, Abt SRBI
              -- Opinions stated in this post are mine only

              Comment


              • #8
                Hi Nick Cox , I am trying to import SAS databases ( .xpt) in Stata 18 using the following command:

                Code:
                import sasxport5 "G:\Call Reports Data\call2009.xpt"
                Stata cannot import some files and produce an error code:

                G:\Call Reports Data\call2009.xpt has string variable textc490 with format (value label) $; value labels for string variables are not allowed in Stata
                r(610);

                How can I fix the problem? Thanks in advance for your cooperation.
                Last edited by S. M. Woahid Murad; 04 Oct 2023, 19:22.

                Comment


                • #9
                  Originally posted by S. M. Woahid Murad View Post
                  How can I fix the problem?
                  Maybe try the novallabels option.
                  Code:
                  import sasxport5 "G:\Call Reports Data\call2009.xpt", novallabels
                  The downside is that you'll lose the value labels for numeric variables, too, if any.

                  Comment


                  • #10
                    Hi Joseph,

                    It works. Thank you so much.


                    Kind Regards,
                    Woahid

                    Comment

                    Working...
                    X