Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform column bind between two datasets in SAS?

Tags:

r

sas

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?

like image 518
Abhishek Avatar asked Dec 14 '22 16:12

Abhishek


2 Answers

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;
like image 54
Longfish Avatar answered Jan 07 '23 17:01

Longfish


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 
like image 30
Math Avatar answered Jan 07 '23 16:01

Math