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
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;
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;
A good approach! I think you want to add SAMPLE to the KEEP list.
@Astounding Thank you Sir!
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
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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.