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 |
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;
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;
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;
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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.