Chiefsfan4ever
Technical User
I have a question about trying to create a new variable in a loop. The idea is that you don't know how many variables you will need and you want it to create the variables as they go along. Below is some sample code of what I want it to do. Maxcount is the maximum of count. Let's just say Maxcount is 2. So I would want variables with the name Bucket1 through Bucket10. Any ideas?
data work2;
set work1;
Extra=0;
retain extra;
NetCount = Maxcount-extra;
if ( NetCount >0 ) and (NetCount = count) then do;
Bucket||(1+5*(Netcount-1))=Bucket1;
Bucket||(2+5*(Netcount-1))=Bucket2;
Bucket||(3+5*(Netcount-1))=Bucket3;
Bucket||(4+5*(Netcount-1))=bucket4;
Bucket||(5+5*(Netcount-1))=bucket5;
end;
Extra = Extra+1;
run;
data work2;
set work1;
Extra=0;
retain extra;
NetCount = Maxcount-extra;
if ( NetCount >0 ) and (NetCount = count) then do;
Bucket||(1+5*(Netcount-1))=Bucket1;
Bucket||(2+5*(Netcount-1))=Bucket2;
Bucket||(3+5*(Netcount-1))=Bucket3;
Bucket||(4+5*(Netcount-1))=bucket4;
Bucket||(5+5*(Netcount-1))=bucket5;
end;
Extra = Extra+1;
run;