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.
Additional info:
I'm using windows 7 and Enterprise Guide 6.1 (64bit)
Thanks in advance,
Tom
Declare an array.
data want;
set have;
array letters(*) a-g;
select=letters(_n_);
run;
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
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;
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.
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.