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
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:
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 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.
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
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:
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.