|
proc sql noprint;
select cats('x',max(count(var,',')+1)) into :num
from test; quit;
data NEED;
set test;
Array ax(*)$ x1 - &num.;
do i=1 to dim(ax);
ax(i) = scan (compress(var),i,',');
end;
drop i;
run;
Daniel Fernandez.
Barcelona
2010/1/20 Stephane COLAS <scolas@datametric.fr>:
> Hi there
>
> I'm wondering if someone could propose something to do that in one data
> step.
>
> Assume you have one variable VAR like that "a,b,c,d,e,f" and you want to
> distribute the contents in several else variables.
>
> I thought to that but I stopped on the way to automatically detect the
> number of variables to create. The goal is to avoid the generation of
> unuseful variables with Array. I thought to use a _temporary_ array but I
> don't figure out how to have the good number of final variables after.
>
> data test;
> var="a,b,c,d,e,f";output;
> var="a,b,c,d,e,f";output;
> run;
>
> data test;
> set test;
>
> count = count(var,' ')+1; /* Is the number of words in VAR*/
>
> Array ax(*) x1-x10; /* Could I specify that the number of variables to
> create is the value in the variable COUNT ? */
> do = i 1 to dim(ax);
> x(i) = scan (var,i,',');
> end;
>
> /*The TEST table will contain the x8 x9 x10 variables without nothing and I
> want to avoid that */
> run;
>
> Any tips ?
>
> Stephane.
>
|