From: Tom Abernathy on 21 Feb 2010 09:39 data a; array x x1-x10; do i=1 to 10; x(i)=i; end; run; On Feb 21, 8:52 am, kuh...(a)126.COM (Clark An) wrote: > %macro a; > > data a; > > %do i=1 %to 10; > > X&i=&i; > > output; > > %end; > > run; > > %mend a; > > If I dont wanna use macro %do,just use do loop,is it possible to do in this > way?The variables names are according to the value of i.Thank you very much! > > data a; > do i=1 to 10; > ... > end; > run; > > The key is the X&j.
From: Arthur Tabachneck on 21 Feb 2010 09:07 Clark, I'm not sure why you would want to build that particular file, but I think that the following data step code accomplishes the same thing: data a (drop=i); array x(10); do i=1 to 10; x(i)=i; output; end; run; HTH, Art --------- On Sun, 21 Feb 2010 08:52:09 -0500, Clark An <kuhasu(a)126.COM> wrote: >%macro a; > > data a; > > %do i=1 %to 10; > > X&i=&i; > > output; > > %end; > > run; > >%mend a; > > >If I dont wanna use macro %do,just use do loop,is it possible to do in this >way?The variables names are according to the value of i.Thank you very much! > >data a; > do i=1 to 10; > ... > end; >run; > >The key is the X&j.
From: Clark An on 21 Feb 2010 10:17 Thank you. Then how abt do i=1 to 10; do j=1 to 15; do k=1 to 100; do l=1 to 20; do m=1 to 17; do n=1 to 23; X&i&j&k&l&m&n=&i+&j+&k+&l+&m+&n; output; end; end; end; end; end; end;
From: xlr82sas on 21 Feb 2010 21:58 On Feb 21, 7:17 am, kuh...(a)126.COM (Clark An) wrote: > Thank you. > > Then how abt > > do i=1 to 10; > do j=1 to 15; > do k=1 to 100; > do l=1 to 20; > do m=1 to 17; > do n=1 to 23; > X&i&j&k&l&m&n=&i+&j+&k+&l+&m+&n; > output; > end; > end; > end; > end; > end; > end; Hi An, Trivial in perl and R not so easy in SAS. Here is a solution using my drop down to R macros on my site. I think you might be able to do it in IML, but I we are better off switching to R? http://homepage.mac.com/magdelina/.Public/ utl_tipweb.txt /* T005210 DROP DOWN TO R IN A DATASTEP /* here is SAS/R solution - it uses R lists */ data _null_; length pgm $1024; /* R CODE */ pgm=compbl(" library(SASxport); library(foreign); vv<-list(); for (i in 1:2) {; for (j in 1:3) {; for (k in 1:4) {; for (l in 1:5) {; vr=paste('x',as.character(i),as.character(j),as.character(k),as.character(l),sep=''); vv[[vr]]<-i*1000+j*100+k*10+l; }; }; }; }; mat2345=data.frame(vv); mat2345; write.xport(mat2345,file='C:\\utl\ \mat2345.xpt',autogen.formats=FALSE);" ); call rxeq(pgm); call getxpt('mat2345'); /* get the detail data from R */ run; proc contents data=mat2345; run; Alphabetic List of Variables and Attributes # Variable Type Len 1 X1111 Num 8 2 X1112 Num 8 3 X1113 Num 8 4 X1114 Num 8 5 X1115 Num 8 6 X1121 Num 8 7 X1122 Num 8
From: Arthur Tabachneck on 21 Feb 2010 21:21 Clark, Possible with a data step but, honestly, this is one that is accomplished better (I think) by using %do in a macro. Art ------------- On Feb 21, 10:17 am, kuh...(a)126.COM (Clark An) wrote: > Thank you. > > Then how abt > > do i=1 to 10; > do j=1 to 15; > do k=1 to 100; > do l=1 to 20; > do m=1 to 17; > do n=1 to 23; > X&i&j&k&l&m&n=&i+&j+&k+&l+&m+&n; > output; > end; > end; > end; > end; > end; > end;
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Oracle Clinical: table RXC_DCI_BOOK_PAGES Next: Macro variable and do loop |