문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top