## Data Step Problem

Solved
Occasional Contributor
Posts: 18

# Data Step Problem

Hi All

I have below data set and I need to repeate the ToB 5 for another 5 time. Please see the data set and want result set.

DATA TEST;

INPUT product_cat \$ Group \$ TOB COUNT;

cards;

X A 1 2

X A 2 3

X A 3 4

X A 4 3

X A 5 5

X B 1 3

X B 2 5

X B 3 6

X B 4 7

X B 5 3

Y A 1 12

Y A 2 13

Y A 3 14

Y A 4 13

Y A 5 15

Y B 1 13

Y B 2 15

Y B 3 16

Y B 4 17

Y B 5 13

;

run;

I want below result from above data set

 product_cat Group TOB COUNT X A 1 2 X A 2 3 X A 3 4 X A 4 3 X A 5 5 X A 6 5 X A 7 5 X A 8 5 X A 9 5 X A 10 5 X B 1 3 X B 2 5 X B 3 6 X B 4 7 X B 5 3 X B 6 3 X B 7 3 X B 8 3 X B 9 3 X B 10 3 Y A 1 12 Y A 2 13 Y A 3 14 Y A 4 13 Y A 5 15 Y A 6 15 Y A 7 15 Y A 8 15 Y A 9 15 Y A 10 15 Y B 1 13 Y B 2 15 Y B 3 16 Y B 4 17 Y B 5 13 Y B 6 13 Y B 7 13 Y B 8 13 Y B 9 13 Y B 10 13

Accepted Solutions
Solution
‎09-20-2016 11:46 AM
Super User
Posts: 6,788

## Re: Data Step Problem

If you have already created TEST, you could try:

data want;

set test;

output;

if tob=5 then do tob=6 to 10;

output;

end;

run;

All Replies
Regular Contributor
Posts: 215

## Re: Data Step Problem

How's this?

``````DATA WORK.TEST;
INPUT product_cat \$ Group \$ TOB COUNT;
if TOB = 5 then do;
do i=1 to 5;
output;
end;
end;
else;
output;
drop i;
cards;
X A 1 2
X A 2 3
X A 3 4
X A 4 3
X A 5 5
X B 1 3
X B 2 5
X B 3 6
X B 4 7
X B 5 3
Y A 1 12
Y A 2 13
Y A 3 14
Y A 4 13
Y A 5 15
Y B 1 13
Y B 2 15
Y B 3 16
Y B 4 17
Y B 5 13
;
run;``````
Solution
‎09-20-2016 11:46 AM
Super User
Posts: 6,788

## Re: Data Step Problem

If you have already created TEST, you could try:

data want;

set test;

output;

if tob=5 then do tob=6 to 10;

output;

end;

run;

Contributor
Posts: 30

## Re: Data Step Problem

Other logic:

Hope this helps.

data want;
set test;
by group notsorted;
output;
if last.group then
do i=1 to 5;
tob+1;
output;
end;
drop i;
run;

Regards,

SJ

☑ This topic is solved.