Desktop productivity for business analysts and programmers

Diagnal Selection

Reply
N/A
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.

abcdefg
11270783433215
22447843433129
344647853112
4556278232481
565347453821
600122900

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

Additional info:

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

Thanks in advance,

Tom

Grand Advisor
Posts: 17,313

Re: Diagnal Selection

Declare an array.

data want;

set have;

array letters(*) a-g;

select=letters(_n_);

run;

Grand Advisor
Posts: 9,567

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: 336

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);
  rc=Read_Array('Have',Have);
  Do j=1 To %Eval(&Columns.-&Lines.+1);
    Do i=1 To 6;
      Diag[i,j]=Have[i,i+j-1];
    End;
  End;
  rc=Write_Array('Want',Diag);
Run;

Ask a Question
Discussion stats
  • 3 replies
  • 288 views
  • 0 likes
  • 4 in conversation