DATA Step, Macro, Functions and more

Data Step Problem

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

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_catGroupTOBCOUNT
XA12
XA23
XA34
XA43
XA55
XA65
XA75
XA85
XA95
XA105
XB13
XB25
XB36
XB47
XB53
XB63
XB73
XB83
XB93
XB103
YA112
YA213
YA314
YA413
YA515
YA615
YA715
YA815
YA915
YA1015
YB113
YB215
YB316
YB417
YB513
YB613
YB713
YB813
YB913
YB1013

 

 


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

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;

View solution in original post


All Replies
Regular Contributor
Posts: 159

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: 5,071

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 SJN
Contributor
Posts: 21

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.

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

Discussion stats
  • 3 replies
  • 239 views
  • 1 like
  • 4 in conversation