From: TFriis on
Hey.

I am trying to convert this vba code to sas code;

For i = 1 To Range("A1").End(xlDown).Row
For j = 1 To Range("A1").End(xlDown).Row
If i = j Then
Cells(i, j + 2).Formula = "=0"
Else:
Cells(i, j + 2).Formula = "=A" & i & "*A" & j
End If
Next j
Next i

Range A contains a vector of values, this vector is made into a matrix
with zeroes in the diagonal and multiples else where.

I'm trying to do this with arrays, but they don't act like they
should!

(my code so far)

data abc;
input Conc @@;
cards;
12 13 14 15 16 17
;
run;

proc sql noprint;
select count(*)
into :OBSCOUNT
from work.abc;
quit;
run;

data new;
array a{&obscount} ;
array b{&obscount,&obscount};
do i = 1 to &obscount;
set work.abc;
a{i} = Conc;
end;
do i=1 to &obscount;
do j=1 to &obscount;
set work.abc;
b{i,j}=a[i]*a[j];
output;
end;
end;
drop i j;
run;

(haven't even begun to look at the diagonal, since this doesn't work!)
From: montura on
I had the same problem when recoding a poisson function from VB to
SAS.
SCL arrays work exactly the same way as VB arrays.

SCL arrays allows three or more dimensions, up to 99 dimensions if
memory serves, while data step arrays are effectively limited to two
dimensions.

From: Richard A. DeVenezia on
On Apr 27, 8:19 am, TFriis <t.fr...(a)gmail.com> wrote:
> Hey.
>
> I am trying to convert this vba code to sas code;
>
> For i = 1 To Range("A1").End(xlDown).Row
>     For j = 1 To Range("A1").End(xlDown).Row
>         If i = j Then
>             Cells(i, j + 2).Formula = "=0"
>         Else:
>             Cells(i, j + 2).Formula = "=A" & i & "*A" & j
>         End If
>     Next j
> Next i
>
> Range A contains a vector of values, this vector is made into a matrix
> with zeroes in the diagonal and multiples else where.
>
> I'm trying to do this with arrays, but they don't act like they
> should!
>
> (my code so far)
>
> data abc;
> input Conc @@;
> cards;
> 12 13 14 15 16 17
> ;
> run;
>
> proc sql noprint;
>  select count(*)
>   into :OBSCOUNT
>   from work.abc;
>  quit;
> run;
>
> data new;
> array a{&obscount} ;
> array b{&obscount,&obscount};
> do i = 1 to &obscount;
>   set work.abc;
>   a{i} = Conc;
> end;
> do i=1 to &obscount;
>   do j=1 to &obscount;
>     set work.abc;
>     b{i,j}=a[i]*a[j];
>    output;
>   end;
> end;
> drop i j;
> run;
>
> (haven't even begun to look at the diagonal, since this doesn't work!)

Perhaps part of your problem is that the VBA code populates cells in a
rectangle -- a table if you will.
The code shown above populates a two dimensional array resulting in
NxN columns in and output table having N rows.

In order to create a table that looks like your matrix you will need
to have N columns and N rows.

------------
data vector;
input Conc @@;
cards;
12 13 14 15 16 17
;
run;


proc sql noprint;
select count(*)
into :COUNT
from work.vector;
quit;

data myMatrix;
array values(&count) _temporary_;
do _n_ = 1 to dim(values);
set vector;
values(_n_) = conc;
end;

array cell(&count);

do i = 1 to dim(values);
do j = 1 to dim(values);
if i = j then
cell(j) = 0;
else
cell(j) = values(i) * values(j);
end;
OUTPUT;
end;

format cell: 6.;
keep cell:;
run;
------------


Richard A. DeVenezia
http://www.devenezia.com
From: montura on
If the full solution is fairly simply then Richards 2D posting will
work. If multiple arrays, 2D and 3D, are necessary, email me direct
and I will show you that SCL structure.

From: Richard A. DeVenezia on
On Apr 27, 10:25 am, montura <montura...(a)gmail.com> wrote:
> I had the same problem when recoding a poisson function from VB to
> SAS.
> SCL arrays work exactly the same way as VB arrays.
>
> SCL arrays allows three or more dimensions, up to 99 dimensions if
> memory serves, while

> data step arrays are effectively limited to two dimensions.

This is patently wrong. DATA Step arrays can have any number of
dimensions.

A variable based array is limited to the maximum number of variables
in the PDV.

From the help file:
"
Note: Starting with SAS 9.1, the maximum number of variables can be
greater than 32,767. The maximum number depends on your environment
and the file's attributes. For example, the maximum number of
variables depends on the total length of all the variables and cannot
exceed the maximum page size.
"

--
Richard A. DeVenezia
http://www.devenezia.com