I am merging two data sets horizontally. Is it possible to first list all the data from table 1 and table 2 columns are empty then list all the data form table 2 where tables 1 columns are empty. In other words, columns should be merged horizontally but data should be merged one table at a time.
If I understand you right then something like below should do.
data table1;
set sashelp.class(obs=3);
run;
data table2;
set sashelp.air(obs=2);
run;
data want;
set table1 table2;
run;
proc print data=want;
run;
If I understand you right then something like below should do.
data table1;
set sashelp.class(obs=3);
run;
data table2;
set sashelp.air(obs=2);
run;
data want;
set table1 table2;
run;
proc print data=want;
run;
Thank you for the quick response. I wanted something like this, only difference is I don't have a fixed count of observations as it is dependent on number of rows for table 1 and 2.
@Froebel wrote:
Thank you for the quick response. I wanted something like this, only difference is I don't have a fixed count of observations as it is dependent on number of rows for table 1 and 2.
The first two data steps were just to create some sample datasets to use in the actual data step that you will use.
Your language is unclear. What does it mean to merge horizontally or merge vertically.
In SAS you can SET datasets together and all rows from all datasets will be preserved. Nothing is "merged" in that case. Other than perhaps that the set of variables that exists in the new dataset is the union of the sets of variables from the various input datasets. See the answer from @Patrick which shows an example. But note that if the intersection of the sets of variable names is not empty there will fewer total variables in the combined dataset, since the values from the like named variables will end up in the same variable.
Or you can MERGE datasets by having the observations match on some key variables. In that case the values from the merged observations will appear on the same output observation. You use a BY statement to tell SAS which variables to use to do the merging (matching).
You can also use a BY statement with a SET statement to interleave the observations from the input datasets based on the values of the BY variables.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.