Hi, I want to list the diagonal horizontal. Any suggestions? I dont have IML.
Hi Anca,
Tx, with a little adjustments it Works to my needs.
Made my day.
thod
Do you mean data that looks like this:
1 . . . .
. 2 . . .
. . 3. . .
. . . 4 .
. . . . 5
To look like this:
1
2
3
4
5
?
Hi,
Yes, or like this:
1 2 3 4 5
So you coukd do this:
data have;
input var1 var2 var3 var4 var5;
datalines;
1 . . . .
. 2 . . .
. . 3. . .
. . . 4 .
. . . . 5
;
data want;
set have;
var_want = max(of var1--var5);
run;
proc transpose data = want out = want_tran;var var_want;run;
But this is assuming that you have missing on the non-diagonal values.
Hi Anca,
Tx, with a little adjustments it Works to my needs.
Made my day.
thod
Hi Again,
Any solution if the non-diagonal values not are missing?
thod
So IML would probably be desired for this.
Otherwise, you will need some sort of array to pass through and somehow tell SAS you want the column+1....
Yeah, I don't know.
Anca.
You could just use an array. e.g.:
data have;
input var1 var2 var3 var4 var5;
datalines;
1 . . . .
. 2 . . .
. . 3. . .
. . . 4 .
. . . . 5
;
data want (keep=var_want);
set have;
array all _all_;
var_want = all(_n_);
run;
Similarly to Art's solution, but horizontal - using a temporary (and automatically retained) array to store the values and then copy back to the PDV in the last row.
data have;
input var1 var2 var3 var4 var5;
datalines;
1 . . . .
. 2 . . .
. . 3. . .
. . . 4 .
. . . . 5
;
data want;
set have end=eof;
array all _all_;
array temps [9999] _temporary_;
temps[_n_]=all[_n_];
if eof then do;
do _t = 1 to dim(all);
all[_t]=temps[_t];
end;
output;
end;
run;
Hi Snoopy369,
Thanx for the answer. Do you also have a solution if I want tje diagonals below this one?
thod
I don't know that "below this one" means, perhaps my math education is lacking. I only know of using 'diagonal' to mean the primary diagonal, either top left to bottom right or top right to bottom left. If you want something else, please explain.
Ok, here is a possible one for horizontal, credit to Data_null_;
data have;
input var1 var2 var3 var4 var5;
retain id 1;
datalines;
1 . . . .
. 2 . . .
. . 3. . .
. . . 4 .
. . . . 5
;
data want;
update have(obs=0) have;
by id;
drop id;
run;
Haikuo
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.