From: xlr82sas on
Hi SAS-Lers,

Clark An posed this problem

data mat;
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;
run;

================================

http://homepage.mac.com/magdelina/.Public/utl.html

utl_tipweb.txt
T005260 DROP DOWN TO SCL IN YOUR DATASTEP

Here is a SCL solution using FCMP and macros on my site.
There are many implications, perhaps this is a more
powerful than the macro language.

Note there is no flashing command window. This is lights out solution.
No troublesome GUI to deal with. Good error messages in you log from
SCL.
However, this will not work in EG and you can't imbed widgets.

data mat2345;
array x[2,3,4,5] x1-x120;
do i=1 to 2;
do j=1 to 3;
do k=1 to 4;
do l=1 to 5;
x[i,j,k,l]=i*j*k*l;
output;
end;
end;
end;
end;
run;

/* this datastep renames x1-x120 to X1111-X2345 */
/* SCL is a much more powerful language then macro */
/* Just put your SCL code after pgm= */
/* SAS 9.2 Windows 2000 */
data _null_;
length pgm $1024;
/* SCL program to rename variables - no macro */
pgm=compbl("
init:
dsid=open('mat2345','v');
if dsid then do;
varn=0;
do i=1 to 2;
do j=1 to 3;
do k=1 to 4;
do l=1 to 5;
varn=varn+1;
nam=cats('X',put(i,1.),put(j,1.),put(k,1.),put(l,1.));
xx=cats('X',put(varn,3.));
rc=modvar(dsid,xx,nam);
end;
end;
end;
end;
end;
rc=close(dsid);
return;");
call pgmutl(pgm);
call sclxeq;
run;

# 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


============================
/* IML solution */

proc iml;
x=shape({0} ,1,120,0);
n=shape({' '},1,120,'x0000');
print n;
idx=0;
do i = 1 to 2;
do j = 1 to 3;
do k = 1 to 4;
do l = 1 to 5;
idx=idx+1;
x[1,idx]=1000*i+100*j+10*k+l;
n[1,idx]=cats('x',char(i,1,0),
char(j,1,0),char(k,1,0),char(l,1,0));
end;
end;
end;
end;
create mat2345 from x[colname=n];
append from x;
close mat2345;
quit;
run;

proc contents;
run;

Alphabetic List of Variables and Attributes


# Variable Type Len


1 X1111 Num 8
2 X1112 Num 8
3 X1113 Num 8


===================================
Here is the R solution

data _null_;
length pgm $1024;
/* R CODE */
pgm=compbl("
library(SASxport);
library(foreign);
vv<-list();
vr="s0000";
vv<-list();
vv[vr]<-0;
mat2345=vv;
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+j;
may2345=data.frame(mat2345,vv);
};
};
};
};
beg;
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

==========================================

Future projects drop down to perl and a Java interface to R.
From: xlr82sas on
On Feb 23, 7:27 pm, xlr82sas <xlr82...(a)aol.com> wrote:
> Hi SAS-Lers,
>
> Clark An posed this problem
>
> data mat;
> 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;
> run;
>
> ================================
>
> http://homepage.mac.com/magdelina/.Public/utl.html
>
> utl_tipweb.txt
> T005260 DROP DOWN TO SCL IN YOUR DATASTEP
>
> Here is a SCL solution using FCMP and macros on my site.
> There are many implications, perhaps this is a more
> powerful than the macro language.
>
> Note there is no flashing command window. This is lights out solution.
> No troublesome GUI to deal with. Good error messages in you log from
> SCL.
> However, this will not work in EG and you can't imbed widgets.
>
> data mat2345;
>   array x[2,3,4,5] x1-x120;
>   do i=1 to 2;
>     do j=1 to 3;
>       do k=1 to 4;
>         do l=1 to 5;
>           x[i,j,k,l]=i*j*k*l;
>           output;
>         end;
>       end;
>     end;
>   end;
> run;
>
> /* this datastep renames x1-x120 to X1111-X2345              */
> /* SCL is a much more powerful language then macro          */
> /* Just put your SCL code after pgm=                        */
> /* SAS 9.2 Windows 2000                                     */
> data _null_;
>    length pgm $1024;
>    /* SCL program to rename variables - no macro */
>    pgm=compbl("
>    init:
>      dsid=open('mat2345','v');
>      if dsid then do;
>        varn=0;
>        do i=1 to 2;
>          do j=1 to 3;
>            do k=1 to 4;
>              do l=1 to 5;
>                varn=varn+1;
>                nam=cats('X',put(i,1.),put(j,1.),put(k,1..),put(l,1.));
>                xx=cats('X',put(varn,3.));
>                rc=modvar(dsid,xx,nam);
>              end;
>            end;
>          end;
>        end;
>       end;
>       rc=close(dsid);
>    return;");
>    call pgmutl(pgm);
>    call sclxeq;
> run;
>
>  #    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
>
> ============================
> /*  IML solution */
>
> proc iml;
>     x=shape({0} ,1,120,0);
>     n=shape({'     '},1,120,'x0000');
>     print n;
>     idx=0;
>     do i = 1 to 2;
>        do j = 1 to 3;
>           do k = 1 to 4;
>              do l = 1 to 5;
>                idx=idx+1;
>                x[1,idx]=1000*i+100*j+10*k+l;
>                n[1,idx]=cats('x',char(i,1,0),
>                char(j,1,0),char(k,1,0),char(l,1,0));
>              end;
>           end;
>        end;
>     end;
>    create mat2345 from x[colname=n];
>    append from x;
>    close mat2345;
> quit;
> run;
>
> proc contents;
> run;
>
> Alphabetic List of Variables and Attributes
>
>   #    Variable    Type    Len
>
>   1    X1111       Num       8
>   2    X1112       Num       8
>   3    X1113       Num       8
>
> ===================================
> Here is  the R solution
>
> data _null_;
>       length pgm $1024;
>       /* R CODE */
>       pgm=compbl("
>       library(SASxport);
>       library(foreign);
>       vv<-list();
>       vr="s0000";
>       vv<-list();
>       vv[vr]<-0;
>       mat2345=vv;
>       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+j;
>            may2345=data.frame(mat2345,vv);
>       };
>         };
>           };
>             };
>       beg;
>       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
>
> ==========================================
>
> Future projects drop down to perl and a Java interface to R.

Hi SAS-Lers,

I may have been wrong when I said 'DROP DOWN TO SCL' will not work
in EG, however I don't know how one could do it properly without at
least starting one SCL GUI interface. My sleazy method of creating an
scl catalog from a binary file required me to do the GUI thing at
least once. I think you would need to go into the GUI on the server at
least once, and I don't see how this is possible in EG.

SCL experts please correct me if I am wrong?

I would be very interested in bootstrap method to create an initial
SCL catalog and SCL program without the GUI. No cheating, you cannot
copy a catalog from some other location or flash a command window. You
application has to work batch lights out on the server and client. The
GUI and flasing command window has prevented me from using SCL in the
past.

Interestingly, my method may open up possibilites for EG and SCL. We
just need a set of catlogs or different environments.
From: xlr82sas on
On Feb 23, 7:27 pm, xlr82sas <xlr82...(a)aol.com> wrote:
> Hi SAS-Lers,
>
> Clark An posed this problem
>
> data mat;
> 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;
> run;
>
> ================================
>
> http://homepage.mac.com/magdelina/.Public/utl.html
>
> utl_tipweb.txt
> T005260 DROP DOWN TO SCL IN YOUR DATASTEP
>
> Here is a SCL solution using FCMP and macros on my site.
> There are many implications, perhaps this is a more
> powerful than the macro language.
>
> Note there is no flashing command window. This is lights out solution.
> No troublesome GUI to deal with. Good error messages in you log from
> SCL.
> However, this will not work in EG and you can't imbed widgets.
>
> data mat2345;
>   array x[2,3,4,5] x1-x120;
>   do i=1 to 2;
>     do j=1 to 3;
>       do k=1 to 4;
>         do l=1 to 5;
>           x[i,j,k,l]=i*j*k*l;
>           output;
>         end;
>       end;
>     end;
>   end;
> run;
>
> /* this datastep renames x1-x120 to X1111-X2345              */
> /* SCL is a much more powerful language then macro          */
> /* Just put your SCL code after pgm=                        */
> /* SAS 9.2 Windows 2000                                     */
> data _null_;
>    length pgm $1024;
>    /* SCL program to rename variables - no macro */
>    pgm=compbl("
>    init:
>      dsid=open('mat2345','v');
>      if dsid then do;
>        varn=0;
>        do i=1 to 2;
>          do j=1 to 3;
>            do k=1 to 4;
>              do l=1 to 5;
>                varn=varn+1;
>                nam=cats('X',put(i,1.),put(j,1.),put(k,1..),put(l,1.));
>                xx=cats('X',put(varn,3.));
>                rc=modvar(dsid,xx,nam);
>              end;
>            end;
>          end;
>        end;
>       end;
>       rc=close(dsid);
>    return;");
>    call pgmutl(pgm);
>    call sclxeq;
> run;
>
>  #    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
>
> ============================
> /*  IML solution */
>
> proc iml;
>     x=shape({0} ,1,120,0);
>     n=shape({'     '},1,120,'x0000');
>     print n;
>     idx=0;
>     do i = 1 to 2;
>        do j = 1 to 3;
>           do k = 1 to 4;
>              do l = 1 to 5;
>                idx=idx+1;
>                x[1,idx]=1000*i+100*j+10*k+l;
>                n[1,idx]=cats('x',char(i,1,0),
>                char(j,1,0),char(k,1,0),char(l,1,0));
>              end;
>           end;
>        end;
>     end;
>    create mat2345 from x[colname=n];
>    append from x;
>    close mat2345;
> quit;
> run;
>
> proc contents;
> run;
>
> Alphabetic List of Variables and Attributes
>
>   #    Variable    Type    Len
>
>   1    X1111       Num       8
>   2    X1112       Num       8
>   3    X1113       Num       8
>
> ===================================
> Here is  the R solution
>
> data _null_;
>       length pgm $1024;
>       /* R CODE */
>       pgm=compbl("
>       library(SASxport);
>       library(foreign);
>       vv<-list();
>       vr="s0000";
>       vv<-list();
>       vv[vr]<-0;
>       mat2345=vv;
>       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+j;
>            may2345=data.frame(mat2345,vv);
>       };
>         };
>           };
>             };
>       beg;
>       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
>
> ==========================================
>
> Future projects drop down to perl and a Java interface to R.

Just one other point. I think it is possible to simplify the 'DROP
DOWN'. I think I can combine the calls to FCMP.
From: Clark An on
Thank you for the solution.

data mat2345;
array x[2,3,4,5] x1-x120;
retain n 0;
do i=1 to 2;
do j=1 to 3;
do k=1 to 4;
do l=1 to 5;
n+1;
...
x[i,j,k,l]=lag&n.(n);
output;
end;
end;
end;
end;
run;

Then how to treat lag function with macro variable?
From: Wensui Liu on
nice code
by the way, the piece related to R looks very interested. is it some
kind of new functionality in SAS? I've never seen before.

On Tue, Feb 23, 2010 at 10:27 PM, xlr82sas <xlr82sas(a)aol.com> wrote:
> Hi SAS-Lers,
>
> Clark An posed this problem
>
> data mat;
> 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;
> run;
>
> ================================
>
> http://homepage.mac.com/magdelina/.Public/utl.html
>
> utl_tipweb.txt
> T005260 DROP DOWN TO SCL IN YOUR DATASTEP
>
> Here is a SCL solution using FCMP and macros on my site.
> There are many implications, perhaps this is a more
> powerful than the macro language.
>
> Note there is no flashing command window. This is lights out solution.
> No troublesome GUI to deal with. Good error messages in you log from
> SCL.
> However, this will not work in EG and you can't imbed widgets.
>
> data mat2345;
> array x[2,3,4,5] x1-x120;
> do i=1 to 2;
> do j=1 to 3;
> do k=1 to 4;
> do l=1 to 5;
> x[i,j,k,l]=i*j*k*l;
> output;
> end;
> end;
> end;
> end;
> run;
>
> /* this datastep renames x1-x120 to X1111-X2345 */
> /* SCL is a much more powerful language then macro */
> /* Just put your SCL code after pgm= */
> /* SAS 9.2 Windows 2000 */
> data _null_;
> length pgm $1024;
> /* SCL program to rename variables - no macro */
> pgm=compbl("
> init:
> dsid=open('mat2345','v');
> if dsid then do;
> varn=0;
> do i=1 to 2;
> do j=1 to 3;
> do k=1 to 4;
> do l=1 to 5;
> varn=varn+1;
> nam=cats('X',put(i,1.),put(j,1.),put(k,1.),put(l,1.));
> xx=cats('X',put(varn,3.));
> rc=modvar(dsid,xx,nam);
> end;
> end;
> end;
> end;
> end;
> rc=close(dsid);
> return;");
> call pgmutl(pgm);
> call sclxeq;
> run;
>
> # 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
>
>
> ============================
> /* IML solution */
>
> proc iml;
> x=shape({0} ,1,120,0);
> n=shape({' '},1,120,'x0000');
> print n;
> idx=0;
> do i = 1 to 2;
> do j = 1 to 3;
> do k = 1 to 4;
> do l = 1 to 5;
> idx=idx+1;
> x[1,idx]=1000*i+100*j+10*k+l;
> n[1,idx]=cats('x',char(i,1,0),
> char(j,1,0),char(k,1,0),char(l,1,0));
> end;
> end;
> end;
> end;
> create mat2345 from x[colname=n];
> append from x;
> close mat2345;
> quit;
> run;
>
> proc contents;
> run;
>
> Alphabetic List of Variables and Attributes
>
>
> # Variable Type Len
>
>
> 1 X1111 Num 8
> 2 X1112 Num 8
> 3 X1113 Num 8
>
>
> ===================================
> Here is the R solution
>
> data _null_;
> length pgm $1024;
> /* R CODE */
> pgm=compbl("
> library(SASxport);
> library(foreign);
> vv<-list();
> vr="s0000";
> vv<-list();
> vv[vr]<-0;
> mat2345=vv;
> 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+j;
> may2345=data.frame(mat2345,vv);
> };
> };
> };
> };
> beg;
> 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
>
> ==========================================
>
> Future projects drop down to perl and a Java interface to R.
>



--
==============================
WenSui Liu
Blog : statcompute.spaces.live.com
Tough Times Never Last. But Tough People Do. - Robert Schuller
==============================