BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Smitha9
Fluorite | Level 6

Hi, I want the columns to rows. please see the below example: A1 A2 A3 is made into one variable and ID will have duplicates. Let me know the code for this. thank you in advance.

 

Example data a:

ID   A           A1       A2

1    3.55     3.65     3.76

2    4.35     3.78     5.67

3.   6.78     7.23     3.43

 

I want the data B to be:

ID       B

1        3.55

1        3.65

1        3.76

2        4.35    

2        3.78    

2        5.67

3        6.78    

3        7.23    

3        3.43

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Transposing data tutorials:

Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/

https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/

Your example is a straighforward transpose.

 

Both are illustrated in the tutorials above.

 

proc transpose data=A out=B;
by ID;
var A A1 A2;
run;

@Smitha9 wrote:

Hi, I want the columns to rows. please see the below example: A1 A2 A3 is made into one variable and ID will have duplicates. Let me know the code for this. thank you in advance.

 

Example data a:

ID   A           A1       A2

1    3.55     3.65     3.76

2    4.35     3.78     5.67

3.   6.78     7.23     3.43

 

I want the data B to be:

ID       B

1        3.55

1        3.65

1        3.76

2        4.35    

2        3.78    

2        5.67

3        6.78    

3        7.23    

3        3.43

 


 

View solution in original post

2 REPLIES 2
Reeza
Super User

Transposing data tutorials:

Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/

https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/

Your example is a straighforward transpose.

 

Both are illustrated in the tutorials above.

 

proc transpose data=A out=B;
by ID;
var A A1 A2;
run;

@Smitha9 wrote:

Hi, I want the columns to rows. please see the below example: A1 A2 A3 is made into one variable and ID will have duplicates. Let me know the code for this. thank you in advance.

 

Example data a:

ID   A           A1       A2

1    3.55     3.65     3.76

2    4.35     3.78     5.67

3.   6.78     7.23     3.43

 

I want the data B to be:

ID       B

1        3.55

1        3.65

1        3.76

2        4.35    

2        3.78    

2        5.67

3        6.78    

3        7.23    

3        3.43

 


 

Astounding
PROC Star

A simple solution:

data want;
   set have;
   B=A;
   output;
   B=A1;
   output;
   B=A2;
   output;
   keep ID B;
run;

More complex (and more flexible) solutions do exist, but this would be sufficient for the problem at hand.