Not applicable
Posts: 1

# Diagnal Selection

Hello,

I have a very basic question that I'm hoping someone can help me with.  Bear with me if I don't include all of the relevant information and if I've missed a post in my searches that covers this topic.

Basically I've used proc freq to generate something like the table below (and the out switch to generate the same data as data set).  I'm looking to select the diagonal line of data which in this case for the A column would be 1,4,4,78,45,0 (a1,b2,c3,d4,e5,f6) and for the B column 2,4,78,23,38,0.

My first thought was to read the data into IML and do some matrix magic on it but I have never used IML and don't have much time to spend on this problem.

 a b c d e f g 1 1 2 70 78 34 33 215 2 2 4 4 78 434 33 129 3 44 6 4 78 5 3 112 4 55 6 2 78 23 24 81 5 6 5 34 7 45 38 21 6 0 0 12 2 9 0 0

I look forward to any clarifying questions you may have for me and hopefully some suggested solutions.

I'm using windows 7 and Enterprise Guide 6.1 (64bit)

Tom

Super User
Posts: 24,004

## Re: Diagnal Selection

Declare an array.

data want;

set have;

array letters(*) a-g;

select=letters(_n_);

run;

Super User
Posts: 10,849

## Re: Diagnal Selection

Yeah. That should be done better via IML . I realy suggest you to post it at SAS/IML Software and Matrix Computations  .

Rick might have a magic function to get it .

```data have;
input      a     b     c     d     e     f     g ;
cards;
1     2     70     78     34     33     215
2     4     4     78     434     33     129
44     6     4     78     5     3     112
55     6     2     78     23     24     81
6     5     34     7     45     38     21
0     0     12     2     9     0     0
;
run;
data want;
set have;
array x{*} _numeric_;
retain offset -1;
offset+1;
do i=1 to dim(x)-offset;
x{i}=x{i+offset};
end;
do i=dim(x)-offset+1 to dim(x);
x{i}=.;
end;
drop i offset;
run;

```

Xia Keshan

Super Contributor
Posts: 355

## Re: Diagnal Selection

Proc FCMP-version:

data have;
input      a     b     c     d     e     f     g ;
cards;
1     2     70     78     34     33     215
2     4     4     78     434     33     129
44     6     4     78     5     3     112
55     6     2     78     23     24     81
6     5     34     7     45     38     21
0     0     12     2     9     0     0
;
run;

%Let Lines=6;
%Let Columns=7;

Proc FCMP NoPrint;
Array Have[1] / NoSymbols;
Call Dynamic_Array (Have,&Lines.,&Columns.);
Array Diag[1] / NoSymbols;
Call Dynamic_Array (Diag,&Lines.,&Columns.-&Lines.+1);