Help using Base SAS procedures

how to do merge

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 111
Accepted Solution

how to do merge

Hi all,

 

I have a dataset of ds1.

data ds1;
infile datalines;
input name1 $ name2 $;
datalines;
G A
A B
I C
B D
;
RUN;

 

I need output like 

NAME1 NAME2
G A
A A
I A
B A
G B
A B
I B
B B
G C
A C
I C
B C
G D
A D
I D
B D

 

I follow in proc sql cartesian join but this output not getting.

Can anyone suggest how it can be done.

Thanks in advance.


Accepted Solutions
Solution
‎11-09-2016 01:16 AM
Frequent Contributor
Posts: 111

Re: how to do merge

[ Edited ]

proc sql;
create table ds_final as
select a.name2, b.name1 from ds1 a cross join ds1 b ;
quit;

 

 

 

Solved thank u

Actually i not mentioning the variables and follow cross join.

select * from ds1 cross join ds1;

 

 

View solution in original post


All Replies
Super User
Posts: 17,912

Re: how to do merge

A cartesian join is correct. Post your code/log and explain how it does not match your desired output. 

Solution
‎11-09-2016 01:16 AM
Frequent Contributor
Posts: 111

Re: how to do merge

[ Edited ]

proc sql;
create table ds_final as
select a.name2, b.name1 from ds1 a cross join ds1 b ;
quit;

 

 

 

Solved thank u

Actually i not mentioning the variables and follow cross join.

select * from ds1 cross join ds1;

 

 

Super User
Posts: 9,687

Re: how to do merge

data ds1;
infile datalines;
input name1 $ name2 $;
datalines;
G A
A B
I C
B D
;
RUN;
proc sql;
select *
 from ds1(keep=name1),ds1(keep=name2) order by 2;
quit;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 187 views
  • 0 likes
  • 3 in conversation