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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 592 views
  • 0 likes
  • 2 in conversation