BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
umesh1
Fluorite | Level 6

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

3 REPLIES 3
paulkaefer
Lapis Lazuli | Level 10

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;
Astounding
PROC Star

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;

SJN
Fluorite | Level 6 SJN
Fluorite | Level 6

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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