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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.