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

Hello All,

I have two data sets:

 

Data set 1:

ID Major  Some more fields

1    A

1    B

2    A

2    B

2    C

 

Data set 2:

ID Minor  Some more fields

1    M

1    N

2    X

2    Y

2    Z

 

I am looking for something like this:

ID   Major_1  Major_2  Major_3  Minor_1 Minor_2 Minor_3

1       A             B                             M            N

2       A             B                             X             Y           Z

 

Kindly let me know how shall I proceed.

 

Thanks in Advance

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Look into PROC TRANSPOSE and MERGE

 

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

 


@avpeshwe wrote:

Hello All,

I have two data sets:

 

Data set 1:

ID Major  Some more fields

1    A

1    B

2    A

2    B

2    C

 

Data set 2:

ID Minor  Some more fields

1    M

1    N

2    X

2    Y

2    Z

 

I am looking for something like this:

ID   Major_1  Major_2  Major_3  Minor_1 Minor_2 Minor_3

1       A             B                             M            N

2       A             B                             X             Y           Z

 

Kindly let me know how shall I proceed.

 

Thanks in Advance


 

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

Do you want to ignore "Some more fields" in both the datasets?

avpeshwe
Calcite | Level 5

No I want some other fields as well. However, I want to create additional columns based on Majors and Minors for single ID. So basically I want a single record for 1 ID.

Reeza
Super User

@avpeshwe wrote:

No I want some other fields as well. However, I want to create additional columns based on Majors and Minors for single ID. So basically I want a single record for 1 ID.


How you plan to combine those matters as well. You'll need to provide more details and data that better reflects your actual scenario if you need assistance. 

avpeshwe
Calcite | Level 5

Hello Reeza,

 

I have attached an excel file that will better explain what I want.

Thanks.

Reeza
Super User

I think the link I posted covers that situation, example 2 to be specific. You would run proc transpose on each data set and the use a merge to combine them into one. 

 

 

Reeza
Super User

Look into PROC TRANSPOSE and MERGE

 

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

 


@avpeshwe wrote:

Hello All,

I have two data sets:

 

Data set 1:

ID Major  Some more fields

1    A

1    B

2    A

2    B

2    C

 

Data set 2:

ID Minor  Some more fields

1    M

1    N

2    X

2    Y

2    Z

 

I am looking for something like this:

ID   Major_1  Major_2  Major_3  Minor_1 Minor_2 Minor_3

1       A             B                             M            N

2       A             B                             X             Y           Z

 

Kindly let me know how shall I proceed.

 

Thanks in Advance


 

avpeshwe
Calcite | Level 5

Thanks Reeza. Proc transpose and merge worked perfectly for me!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1437 views
  • 0 likes
  • 3 in conversation