Pregunta

I have a variable with 54 observations. How do I make the variable repeat several times over in a dataset?

ex:

Var1   Var2   Var3
 2       4      5
 4       5      7
 6       3      6

but I want it to look like

Var1   Var2   Var3
 2       4      5
 4       5      7
 6       3      6
 2       4      5
 4       5      7
 6       3      6
 2       4      5
 4       5      7
 6       3      6

edit:

I'm trying to do in SAS what is done in R by:
x = cbind(1.5, 17, 2.5, 12, 19.3) y = rep(x,times=4) y

I have a do loop in SAS but it just repeats each observation instead of repeating the entire vector.

¿Fue útil?

Solución

If you want the entire dataset duplicated, in order, you would repeat the set statement.

data want;
do _iter = 1 to 4;
  do _n_ = 1 to nobs_c;
    set sashelp.class nobs=nobs_c point=_n_;
    output;
  end;
end;
stop;
run;

Of course, you could also just do

data want;
set sashelp.class;
do _n_ = 1 to 4;
  output;
end;
run;

and then just sort the dataset by whatever is appropriate.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top