Announcement

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

  • read in SAS file in Stata15

    Hi,

    Does anyone know if there is a easy way to read in regular SAS files (not SAS xport files) in Stata 15?

    The user written program "usesas using" is not working for Stata 15. Besides Statstransfer, is there any other easier way to do it?

    Thanks,

    Alice

  • #2
    You could always write a text file out of SAS. Otherwise, Ii'd look to see if SAS will export into other formats one of which might import easily into Stata. But Stattransfer is probably the easiest solution.

    Comment


    • #3
      What is the error you are getting with usesas?
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        usesas does require that you have SAS, and also may require some setup first. See the help file.

        If you do have SAS but can't get usesas to work, you could probably get sas to save in some other format.

        If you don't have SAS it really isn't a Stata 15 problem. You may need stattransfer if you have no other program that can read sas files.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          SAS will write Stata formatted files. Something called PROC EXPORT:

          https://stats.idre.ucla.edu/other/mu...file-in-stata/

          NB: I don't use SAS, so I've never tried this, but I often share this link with others who need to pass me datasets within restricted environments (where there's no Stat/Transfer).

          Comment


          • #6
            Thanks to everyone who responded to my question.

            Sorry I am being late getting back to this.

            Richard ---

            Here is the error message I got (BTW, I do have SAS 9.4 on my network server):

            local d1 "20171103"

            . ** Thursday
            .
            . local dt1 "rti_survey_`d1'"

            .
            . usesas using `dt1', clear
            The usesas command uses the savastata SAS macro to load the SAS dataset into memory.
            Large datasets may take a few minutes.
            directory C:\Program Files (x86)\Java\jre1.8.0_141 not found
            directory C:\Program Files (x86)\Java\jre1.8.0_141 not found
            invalid syntax
            invalid syntax
            invalid syntax
            invalid syntax
            directory C:\Program Files\SPSS\Statistics\24\JRE\bin not found
            directory C:\Program Files\SPSS\Statistics\24\JRE\bin not found
            directory C:\Program Files\Mplus-Student\ not found
            directory C:\Program Files\Mplus-Student\ not found
            Edit your sasexe.ado file to set the location *
            of your SAS executable file. *
            \\CPC-UTILITY1\Win9x\Stata15\ado\site\s\sasexe.ado
            *! sasexe Version 2.3 [email protected] 11Apr2012
            *! the carolina population center, unc-ch
            edit sasexe.ado (click, to edit the sasexe.ado file, remember to save when done.)
            usesas requires that you have a working version of SAS on this computer.

            How should I fix it?

            Thanks!

            Alice

            Comment


            • #7
              If you have recent versions of the programs usesas tries to call, you may have to edit some of these ado files. In particular, it looks like usesas only looks for SAS versions up to 9.3.

              I think using `proc export` in SAS is a good suggestion. You can specify a SAS file rather than a working data set, e.g.
              ```
              PROC EXPORT DATA= "inputfile.sas7bdat"
              OUTFILE= "outputfile.dta";
              RUN;
              ```

              The only thing I would add is, after you bring the exported data into Stata, use the `compress` command - SAS stores everything as double-byte floats.
              Last edited by Doug Hemken; 01 Dec 2017, 04:22.
              Doug Hemken
              SSCC, Univ. of Wisc.-Madison

              Comment


              • #8
                Doug,

                Thanks for your response. This is pretty helpful. I can try to do that in SAS instead of Stata.

                But just to keep it as an alternative, do you know how I can fix the ado file of usesas for version control? Is it an easy fix or hard to tackel?

                Thanks!

                Alice

                Comment


                • #9
                  There is a clickable link on the `help usesas` page, almost at the very bottom. As I understand it, you need to edit line 45 in "sasexe.ado". (I haven't actually tried this.)
                  Doug Hemken
                  SSCC, Univ. of Wisc.-Madison

                  Comment


                  • #10
                    Thanks Doug. I'll take a look. - Alice

                    Comment


                    • #11
                      Dear all,

                      I have looked for this solution many times and the response is: there is no way if you don't have SAS installed or Stat Transfer.

                      But it's actually very easy in R. If you are a bilingual Stata/R user, this might be helpful

                      Code:
                      library(haven)
                      library(foreign)
                      data <- read_sas("data.sas7bdat")
                      write.dta(data, "data.dta")
                      Sebastián

                      Comment


                      • #12
                        Thanks Sebastian! I'll use this with R. - Alice

                        Comment

                        Working...
                        X