Reputation: 607
I have these data, looking something like this:
data test;
input ID $ Week Age Weight City $ Sex $;
datalines;
John 2 64 145 OK M
Gary 3 46 176 OM M
;
run;
So, here I have to rows, and I wish to do the following: -duplicate each row as many times needed to get every combination of changing the three variables Week,Weight and City with -1, 0 and +1. E.g., the first row would be multiplied 3*3*3 times:
John 1 63 144 OK M
John 1 63 145 OK M
John 1 63 146 OK M
John 1 64 144 OK M
John 1 64 145 OK M
John 1 64 146 OK M
... etc
I'm thinking something like a loop:
data test2;
set test;
do i = -1 to 1;
do j = -1 to 1;
do k = -1 to 1;
end;
end;
output;
end;
run;
, but I cannot see how to set this up properly.
Upvotes: 2
Views: 1971
Reputation: 21264
You're almost there, you need to add the increments for the variables.
data test;
input ID $ Week Age Weight City $ Sex $;
datalines;
John 2 64 145 OK M
Gary 3 46 176 OM M
;
run;
data want;
set test;
do j=-1 to 1;
weight = weight + j;
do k=-1 to 1;
age = age + k;
do l = -1 to 1;
week = week + l;
output;
end;
end;
end;
drop j k l;
run;
Upvotes: 2