Reputation: 427
I need to create a variable for week0-week187 and doing that RBAR is just that. data looks like:
ID WEEK
1 0
1 28
1 186
2 187
2 30
I am trying to make week0-week187 variables that will be 1 or 0 if the observation is in a given week, should look something like this
ID WEEK WEEK0 WEEK1 ...WEEK28 ... WEEK30...WEEK186 WEEK187
1 0 1 0 ...0...0...0 0
1 28 0 0 ... 1 ... 0 ... 0 0
1 186 0 0 ... 0 ... 0 ... 1 0
2 187 0 0 ... 0 ... 0 ... 0 1
2 30 0 0 ... 0 ... 1 ... 0 0
maybe a DO statement is necessary? most of the time proc sql is causing SAS to crash because my computer is a junkpiece. SAS code is preferred
Upvotes: 0
Views: 156
Reputation: 63424
After the note "don't do this", here is how:
data have;
week=5;
run;
data want;
set have;
array weeks week0-week187;
do _t = 1 to dim(weeks);
weeks[_t]=0;
end;
weeks[week+1]=1;
run;
Far preferable if you need this 'wide' would be to transpose things so you had 1 row per ID variable, I'd guess, which is pretty easy to do as well. But odds are whatever you need this wide format for can be done as easily/more easily without widening.
Upvotes: 1