Solved
Contributor
Posts: 23

# Merge

data test;
input accounts;
datalines;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
;
run;

data test2;
input managers\$;
datalines;
a
b
c
;
run;

i have these two data sets i want an output of

1 a

2 b

3 c

4 a

5 b

6 c

7 a

8 b

9 c

10 a

11 b

12 c

13 a

14 b

15 c

plz help me with any logic if possible.

Accepted Solutions
Solution
‎06-28-2016 02:08 PM
Super User
Posts: 6,785

## Re: Merge

While I agree with the sentiment ... why would you want to ... it's not that lengthy.

data want;

set test;

recno = mod(_n_, 3);

if recno=0 then recno=3;

set test2 point=recno;

drop recno;

run;

All Replies
Super User
Posts: 5,888

## Re: Merge

What could possibly be the real business rule behind this operation?

Data never sleeps
Solution
‎06-28-2016 02:08 PM
Super User
Posts: 6,785

## Re: Merge

While I agree with the sentiment ... why would you want to ... it's not that lengthy.

data want;

set test;

recno = mod(_n_, 3);

if recno=0 then recno=3;

set test2 point=recno;

drop recno;

run;

Contributor
Posts: 23

## Re: Merge

thanks buddy need this for some project which involves a concept of this.

Frequent Contributor
Posts: 120

## Re: Merge

Hi Astounding,

Thanks for providing us an excellent example of use of multiple set statments for combining datasets having many to many relationship. is there any alternative way? Just curious to know to increase the knowledge base.

Regards,

Deepak

Swain
Super User
Posts: 6,785

## Re: Merge

Well, I suppose you could get the same observations, but in a different order, this way:

data want;

set test2;

do _i_=_n_ to _nobs_ by 3;

if _i_ <= _nobs_ then do;

set test point=_i_ nobs=_nobs_;

output;

end;

end;

run;

It's untested code, but looks like it should work.

Frequent Contributor
Posts: 120

## Re: Merge

Hi Astounding,

I was actually looking for an approaching other than using multiple sets statement.

Regards,

Deepak

Swain
🔒 This topic is solved and locked.