I have two data sets containing the same number of rows. I want to perform column bind on the two datasets to create a third dataset. How can we perform this in SAS?
This can be done in R using cbind(), is there an equivalent in SAS?
A simple merge should work in SAS. If you leave out the by
statement then it will merge on row number. First check the setting of the mergenoby
option to make sure it isn't set to error.
proc options option=mergenoby;
run;
If it is set to error then run the following statement before the merge.
option mergenoby=nowarn;
Otherwise this merge statement will join the 2 datasets by row number.
data ds1;
input a b c;
datalines;
1 2 3
6 7 8
11 12 13
;
run;
data ds2;
input d e;
datalines;
4 5
9 10
14 15
;
run;
data ds3;
merge ds1 ds2;
run;
You can use ||
function
example :
proc iml;
x1=j(5,1,1);
x2=j(5,1,2);
data1=x1||x2;
x1=j(5,1,3);
x2=j(5,1,4);
data2=x1||x2;
data=data1||data2;
print data;
run;
quit;
results :
data
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With