BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thod
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
thod
Calcite | Level 5

Hi Anca,

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

Made my day.

thod

View solution in original post

11 REPLIES 11
AncaTilea
Pyrite | Level 9

Do you mean data that looks like this:

1 . . . .

. 2 . . .

. . 3. . .

. . . 4 .

. . . .  5

To look  like this:

1

2

3

4

5

?

Smiley Happy

thod
Calcite | Level 5

Hi,

Yes, or like this:

1 2 3 4 5

AncaTilea
Pyrite | Level 9

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.

Smiley Happy

thod
Calcite | Level 5

Hi Anca,

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

Made my day.

thod

thod
Calcite | Level 5

Hi Again,

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

thod

AncaTilea
Pyrite | Level 9

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.

art297
Opal | Level 21

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;

snoopy369
Barite | Level 11

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;

thod
Calcite | Level 5

Hi Snoopy369,

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

thod

snoopy369
Barite | Level 11

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.

Haikuo
Onyx | Level 15

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 11 replies
  • 825 views
  • 4 likes
  • 5 in conversation