BookmarkSubscribeRSS Feed
yoyong
Obsidian | Level 7

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.

         

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 910 views
  • 0 likes
  • 2 in conversation