BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

data t1; input x y; cards; 1 2 2 3 ; run; data t2; input x y; cards; 2 5 3 6 4 9 ; run; I want output: -------------------- x y x y 1 2 2 5 1 2 3 6 1 2 4 9 2 3 2 5 2 3 3 6 2 3 4 9

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Two variables can't have the same name in SAS. Other than that, this code gives you what you want

 

data t1; 
input x y; 
cards; 
1 2 
2 3 
; 
run; 

data t2; 
input x y; 
cards; 
2 5 
3 6 
4 9 
; 
run;

data want;

   set t1;

   do i=1 to n;
      set t2(rename=(x=x2 y=y2)) point=i nobs=n;
      output;
   end;

run;

proc print data=want;
run;

Result:

 

 

Capture.PNG

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

@BrahmanandaRao 

If you want us to spend time for you then you need to spend a bit more time for asking the question.

To post code please use one of the following icons Capture.JPG so that things don't turn up as badly as what you're giving us.

 

And to address your implicit question:

You're after a Cartesian Product. That's done using a SQL JOIN. If this is homework and you've been asked to use a data step merge then it's important that you read in the documentation about joining/merging data sets and start to understand the difference between a SAS Data Step Merge and a SQL JOIN.

Kurt_Bremser
Super User

Please use the proper methods for posting code and results. Right now one has to guess, given your spaghetti post.

 

Code is best posted with the "little running man" icon, textual data and logs with the {i} button. Help us to help you, it's not rocket science.

 


@BrahmanandaRao wrote:
data t1; input x y; cards; 1 2 2 3 ; run; data t2; input x y; cards; 2 5 3 6 4 9 ; run; I want output: -------------------- x y x y 1 2 2 5 1 2 3 6 1 2 4 9 2 3 2 5 2 3 3 6 2 3 4 9

 

PeterClemmensen
Tourmaline | Level 20

Two variables can't have the same name in SAS. Other than that, this code gives you what you want

 

data t1; 
input x y; 
cards; 
1 2 
2 3 
; 
run; 

data t2; 
input x y; 
cards; 
2 5 
3 6 
4 9 
; 
run;

data want;

   set t1;

   do i=1 to n;
      set t2(rename=(x=x2 y=y2)) point=i nobs=n;
      output;
   end;

run;

proc print data=want;
run;

Result:

 

 

Capture.PNG

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1103 views
  • 0 likes
  • 4 in conversation