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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1041 views
  • 2 likes
  • 3 in conversation