how to replicate rows? Is this a merge?

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

how to replicate rows? Is this a merge?

Thanks for reading!

data   tmp1;

input acct_nbr;

cards;

1

2

data   tmp2;

input thing $;

cards;

a

b

Using above data, how do I create this output:


acct_nbr thing

1 a

1 b

2 a

2 b







Accepted Solutions
Solution
‎05-01-2013 11:44 AM
Super Contributor
Posts: 1,636

Re: how to replicate rows? Is this a merge?

Posted in reply to carterson2

Hi ,

I would not call it a merge.

data   tmp1;

input acct_nbr;

cards;

1

2

data   tmp2;

input thing $;

cards;

a

b

;

data want;

set tmp1;

  do i=1 to nobs;

    set tmp2 nobs=nobs point=i;

output;

   end;

proc print;run;

View solution in original post


All Replies
Super User
Posts: 19,815

Re: how to replicate rows? Is this a merge?

Posted in reply to carterson2

A cross join in SQL will do it.

You can also google cross join in datastep to see ways to do it in a data step.

Contributor
Posts: 25

Re: how to replicate rows? Is this a merge?

this is the best solution, but since no code sample provided, I just marked it as helpful....

Solution
‎05-01-2013 11:44 AM
Super Contributor
Posts: 1,636

Re: how to replicate rows? Is this a merge?

Posted in reply to carterson2

Hi ,

I would not call it a merge.

data   tmp1;

input acct_nbr;

cards;

1

2

data   tmp2;

input thing $;

cards;

a

b

;

data want;

set tmp1;

  do i=1 to nobs;

    set tmp2 nobs=nobs point=i;

output;

   end;

proc print;run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 321 views
  • 3 likes
  • 3 in conversation