sasdatastep

Data step merge without using BY(id)


I need to merge two datasets like the ones below using a data step:

Data have1;
x=1; output;
x=2; output;
x=3; output;
Run;

Data have2;
y = 'A';
z = 'B';
Run;

Data want;
Merge have1 have2;
Run;

The result should be the following:

x   y   z
1   A   B
2   A   B
3   A   B

However when I run the merge SAS only merges the first row and gives me the following:

x   y   z
1   A   B
2   
3   

I know this can be done using a left join, however in order to process the variables in the full dataset I would prefer doing it via a merge. Can anyone help please?


Solution

  • Where did variable Z come from? I think this may be what you want.

    Data want;
       set have1;
       if _n_ eq 1 then set have2;
       Run;