Announcement

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

  • Importing multiple sas-files and saving them as stata-files

    Hi everbody

    I need to import 291 sas-files and convert them to stata-files. The files are e.g. called:
    b1
    b2
    ...
    b50
    k1
    ...
    k10
    l1
    l_e2
    lq1993

    etc.

    So their names are not systematic in anyways.

    Is there a way to loop through all the datasets, thus importing the sas-files and saving them as stata-files?

    If possible, I would like to import the sas-files located in one folder and store the converted stata-files in another folder.

    Best,
    Gustav
    Last edited by Gustav Egede Hansen; 09 Apr 2025, 04:09.

  • #2
    Well, if they're all located in the same folder, you could do something like
    Code:
    local filelist: dir "/my/sas/folder" files "*.sas7bdat"
    
    foreach f of local filelist {
        import sas using "/my/sas/folder/`f'", clear
        local f = subinstr("`f'", ".sas7bdat", ".dta", 1)
        save "my/stata/folder/`f'", replace
       }

    Comment


    • #3
      It worked! Thank you so much!

      Comment

      Working...
      X