## Diagonal as horizontal

Solved
Occasional Contributor
Posts: 5

# Diagonal as horizontal

Hi, I want to list the diagonal horizontal. Any suggestions? I dont have IML.

Accepted Solutions
Solution
‎10-23-2013 08:23 AM
Occasional Contributor
Posts: 5

## Re: Diagonal as horizontal

Hi Anca,

Tx, with a little adjustments it Works to my needs.

thod

All Replies
Super Contributor
Posts: 543

## Re: Diagonal as horizontal

Do you mean data that looks like this:

1 . . . .

. 2 . . .

. . 3. . .

. . . 4 .

. . . .  5

To look  like this:

1

2

3

4

5

?

Occasional Contributor
Posts: 5

## Re: Diagonal as horizontal

Hi,

Yes, or like this:

1 2 3 4 5

Super Contributor
Posts: 543

## Re: Diagonal as horizontal

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.

Solution
‎10-23-2013 08:23 AM
Occasional Contributor
Posts: 5

## Re: Diagonal as horizontal

Hi Anca,

Tx, with a little adjustments it Works to my needs.

thod

Occasional Contributor
Posts: 5

## Re: Diagonal as horizontal

Hi Again,

Any solution if the non-diagonal values not are missing?

thod

Super Contributor
Posts: 543

## Re: Diagonal as horizontal

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.

PROC Star
Posts: 8,164

## Re: Diagonal as horizontal

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;

Super Contributor
Posts: 320

## Re: Diagonal as horizontal

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;

Occasional Contributor
Posts: 5

## Re: Diagonal as horizontal

Hi Snoopy369,

Thanx for the answer. Do you also have a solution if I want tje diagonals below this one?

thod

Super Contributor
Posts: 320

## Re: Diagonal as horizontal

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.

Posts: 3,167

## Re: Diagonal as horizontal

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

🔒 This topic is solved and locked.