1/21/2024 0 Comments Sas merge by![]() It's easy to concatenate SAS datasets vertically (by stacking them on top of each other) but I want to figure out how to do this "horizontally." I don't know PROC SQL and don't know if there's a good way to do this without using this PROC. What I want to make is a single table that looks like this: I then save the ParameterEstimate table to a dataset coefficients2. As Reeza and LinusH suggested, your choices to really get a one-to-many merge will be to reduce the observations in one dataset or the other so you have a unique value (1 obs) for ID in one of the files OR to find another. Let's say I run a second regression using identical code, except that I use a different outcome variable (say, HEALTH). The OP is not doing a one to many merge, the OP is trying to do a many-to-many merge, which might produce undesired results. The dataset coefficients might look something like this: Ods output ParameterEstimate = coefficients (keep = Parameter Estimate Probt) Model spending = age sex region /solution Let's say I'm running a regression using PROC SURVEYREG (note that the variable Probt is the p value): I want to create a Word file that contains all of the coefficients and p values in a single table, like one that you might present in a journal article. I'm running seven regressions on multiple outcomes using the same model specification. Note: You can find the complete documentation for the SAS merge statement. In this section, you will learn about two types of merging: one-to-one merging and match merging. The new data set contains all variables from all the original data sets unless you specify otherwise. Notice that only the rows where a value exists in both datasets are returned. Merging combines observations from two or more SAS data sets into a single observation in a new SAS data set. We can use the following merge statement with (in = a) and (in = b) to merge the two datasets based on the value in the ID column and return only the rows where a value exists in both datasets: /*perform merge*/ Example 4: Return Rows where Value Exists in Both Datasets (in = a) and (in = b) Notice that only the rows where a value exists in the second dataset are returned. We can use the following merge statement with (in = b) to merge the two datasets based on the value in the ID column and return only the rows where a value exists in the second dataset: /*perform merge*/ Example 3: Return Rows where Value Exists in Second Dataset (in = b) Notice that only the rows where a value exists in the first dataset are returned. We can use the following merge statement with (in = a) to merge the two datasets based on the value in the ID column and return only the rows where a value exists in the first dataset: /*perform merge*/ Example 2: Return Rows where Value Exists in First Dataset (in = a) Notice that all rows from both datasets are returned, regardless if there are missing values due to an ID value not existing in both datasets. We can use the following merge statement without any IN statement to merge the two datasets based on the value in the ID column and return all rows from both datasets: /*perform merge*/ The following examples show how to use each method in practice with the following two datasets: /*create first dataset*/ This particular example merges the datasets called data1 and data2 and only returns the rows where a value exists in both data1 and data2. Method 3: Return Rows where Value Exists in Both Datasets (in = a) and (in = b) data final_data This particular example merges the datasets called data1 and data2 and only returns the rows where a value exists in data2. Method 2: Return Rows where Value Exists in Second Dataset (in = b) data final_data This particular example merges the datasets called data1 and data2 and only returns the rows where a value exists in data1. Method 1: Return Rows where Value Exists in First Dataset (in = a) data final_data Here are a few common ways to use the IN statement in practice: When merging two datasets in SAS, you can use the IN statement to only return rows where a value exists in a particular dataset.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |