Announcement

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

  • Tricky: Merging SAS data to a stata dataset

    Hello all! I have a question regarding sas data and Stata data (unfortunately they are restricted so I can't attach the datasets). I have one dataset already perfect on Stata. Then I have a dataset XXXXX.sas7bdat that needs to be merged. (There is not the same variable names from this data set, rather different variables.) I am having issues, any ideas? Advance thank you!

  • #2
    This is very vague. I can appreciate that you actual data are restricted, but you might consider posting similar data that reproduces the problem you are facing. It's best to present some data using -dataex- when asking for help with code. See the FAQ for details.

    I assume you are using Stata 16 or 17 which has frames and the ability to -import sas- data. What follows is general advice. First load each dataset to their own frame. Then use -frlink- to define how dataset linkage is define. Using frames does not require linking variables to have the same name. For more info, see -help frames intro-.

    Another option could use -merge-, which you can also read about from -help merge-. Using merge requires that linking variables have the same name

    Comment


    • #3
      To Leonardo's advice I would add advice that reflects my risk aversion.

      I would separate the process of reading the SAS dataset into Stata from the process of combining the two datasets. Start by importing the SAS dataset and saving it as a Stata dataset. Review it carefully and make sure everything is as you expect it to be. Rerun the import with additional code to take care of any problems. If you're comfortable with merging datasets, this is a good point to rename the variables you'd merge on to match the names in the SAS dataset.

      Then in a separate task, merge the Stata version of your SAS dataset to your other dataset.

      Comment

      Working...
      X