Hi.
I have the following variables from a subset data:
Obs A1 A2 A3 B1 B2 B3 C1 C2 C3 ....
1
2
3
4
5
How do I merge all A variables to become one column, similarly for B and C?
Some rows maybe totally empty e.g. (Row 3) . How do I exclude such rows in the code?
The output will look like:
Obs A B C ....
1
2
4
5
1
2
4
5
1
2
4
5
Thank you.
Something like this?
data have;
input A1 A2 A3 B1 B2 B3 C1 C2 C3;
datalines;
1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 6
5 7 2 0 8 6 5 8 6
4 6 3 9 7 1 6 9 7
4 8 3 5 8 3 1 6 9
;
data want(keep= A B C);
set have;
array As{*} A:;
array Bs{*} B:;
array Cs{*} C:;
do i=1 to dim(As);
A=As[i];B=Bs[i];C=Cs[i];
output;
end;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.