## New arrange to data, 2 columns to 2 rows

Solved
Frequent Contributor
Posts: 115

# New arrange to data, 2 columns to 2 rows

Hi there SAS friends:

My question is quite simple, and i will describe it here in this table:

i have this arrange:

 Sample A B C D E F G H I J K L M N O P Q R 1 255 341 154 154 238 238 ? ? 253 253 134 134 117 125 116 116 ? ? 2 255 335 154 154 238 250 101 101 239 253 134 134 117 125 116 116 107 115 3 255 319 154 154 238 238 101 109 239 253 134 134 117 125 116 116 107 115 4 ? ? 154 154 238 260 101 109 239 253 134 134 125 125 116 116 107 115 5 255 255 154 154 238 238 101 109 239 253 132 134 117 125 116 116 107 115

and the arrange i'm looking for is:

 A/B C/D E/F G/H I/J K/L M/N O/P Q/R 1 255 154 238 ? 253 134 117 116 ? 1 341 154 238 ? 253 134 125 116 ? 2 255 154 238 101 239 134 117 116 107 2 335 154 250 101 253 134 125 116 115 3 255 154 238 101 239 134 117 116 107 3 319 154 238 109 253 134 125 116 115 4 ? 154 238 101 239 134 125 116 107 4 ? 154 260 109 253 134 125 116 115 5 255 154 238 101 239 132 117 116 107 5 255 154 238 109 253 134 125 116 115

It can be noted that the irst row, in the forst table, become the first and second rows in the secind table, this arrange is new for me. i will thank you a lot because i have 500observations and make it manualy will be dificult to proceed..

thanks you very much

Accepted Solutions
Solution
‎12-17-2017 06:44 AM
PROC Star
Posts: 1,558

## Re: New arrange to data, 2 columns to 2 rows

[ Edited ]

data have;
input ( Sample A B C D E F G H I J K L M N O P Q R) (\$);
datalines;
1 255 341 154 154 238 238 ? ? 253 253 134 134 117 125 116 116 ? ?
2 255 335 154 154 238 250 101 101 239 253 134 134 117 125 116 116 107 115
3 255 319 154 154 238 238 101 109 239 253 134 134 117 125 116 116 107 115
4 ? ? 154 154 238 260 101 109 239 253 134 134 125 125 116 116 107 115
5 255 255 154 154 238 238 101 109 239 253 132 134 117 125 116 116 107 115
;
data want;
set have;
array ar(*) a--r;
output;
do _n_=1 by 2 to dim(ar);
ar(_n_)=ar(_n_+1);
end;
output;
keep a c e g i k m o q;
run;

All Replies
Solution
‎12-17-2017 06:44 AM
PROC Star
Posts: 1,558

## Re: New arrange to data, 2 columns to 2 rows

[ Edited ]

data have;
input ( Sample A B C D E F G H I J K L M N O P Q R) (\$);
datalines;
1 255 341 154 154 238 238 ? ? 253 253 134 134 117 125 116 116 ? ?
2 255 335 154 154 238 250 101 101 239 253 134 134 117 125 116 116 107 115
3 255 319 154 154 238 238 101 109 239 253 134 134 117 125 116 116 107 115
4 ? ? 154 154 238 260 101 109 239 253 134 134 125 125 116 116 107 115
5 255 255 154 154 238 238 101 109 239 253 132 134 117 125 116 116 107 115
;
data want;
set have;
array ar(*) a--r;
output;
do _n_=1 by 2 to dim(ar);
ar(_n_)=ar(_n_+1);
end;
output;
keep a c e g i k m o q;
run;

Super User
Posts: 6,626

## Re: New arrange to data, 2 columns to 2 rows

A good approach!  I think you want to add SAMPLE to the KEEP list.

PROC Star
Posts: 1,558

## Re: New arrange to data, 2 columns to 2 rows

@Astounding  Thank you Sir!

Frequent Contributor
Posts: 115

## Re: New arrange to data, 2 columns to 2 rows

Awesome:

just correct to:

data want;
set have;
array ar(*) a--r;
output;
do _n_=1 by 2 to dim(ar);
ar(_n_)=ar(_n_+1);
end;
output;
keep Sample a c e g i k m o q;
run;

proc print data = want;
run;

Keep SAMPLE;

Best regards

PROC Star
Posts: 1,558

## Re: New arrange to data, 2 columns to 2 rows

[ Edited ]

Yes @jonatan_velarde  Thank you. I realised that later. Sorry I was awfully sleepy last night when i wrote it. Anyways, the same problem is actually even more easy to solve using proc iml. I will have that discussion for later as I am still tired Have a good sunday

☑ This topic is solved.

Discussion stats
• 5 replies
• 219 views
• 2 likes
• 3 in conversation