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

How can I change the dataset

like this

 

x1 y1 5

x2 y1 2

x1 y2 4

x2 y2 3

 

into this

 

      y1 y2

x1  5   4

x2  2   3

 

It will be graceful if someone can help me out!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc sort data=have;
    by x;
run;
proc transpose data=have out=want;
    by x;
    id y;
    var column3;
run;

Since you didn't provide variable names, I chose my own variable names. I hope you can figure out which name corresponds to which variable.

 

In the future, please provide variable names.

 

In the future, please provide (a portion of) your data as a SAS data step, as explained here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

--
Paige Miller

View solution in original post

3 REPLIES 3
Jonathanzz
Obsidian | Level 7
Actually, my data has over 1000 x and y variables. Can I do it with array?
PaigeMiller
Diamond | Level 26
proc sort data=have;
    by x;
run;
proc transpose data=have out=want;
    by x;
    id y;
    var column3;
run;

Since you didn't provide variable names, I chose my own variable names. I hope you can figure out which name corresponds to which variable.

 

In the future, please provide variable names.

 

In the future, please provide (a portion of) your data as a SAS data step, as explained here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

--
Paige Miller
Jonathanzz
Obsidian | Level 7
Thanks a lot! You are my hero!

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!

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