BookmarkSubscribeRSS Feed
thundergeek
Calcite | Level 5

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

3 REPLIES 3
Reeza
Super User

Declare an array.

data want;

set have;

array letters(*) a-g;

select=letters(_n_);

run;

Ksharp
Super User

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

user24feb
Barite | Level 11

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 865 views
  • 0 likes
  • 4 in conversation