Hello,
I am having trouble going from long to wide using Proc transpose.
It seems like it should be really simple but I'm not getting it correct:
Trying to go from:
ID grade
1 grade1
1 grade2
1 grade3
2 grade1
2 grade2
2 grade3
3 grade1
3 grade2
3 grade3
to:
ID grade1 grade2 grade3
1 88 82 89
2 76 87 90
3 99 94 89
I tried
**proc transpose from long to wide;
proc transpose data=long out=wide (drop=_NAME) prefix=grade;
by ID;
id grade1-grade3;
run;
Proc print data=wide;
title ' Transpose from Long to Wide';
run;
PROC TRANSPOSE is not the easiest thing to learn. What you are looking for might be as simple as this:
proc transpose data=long out=wide (drop=_NAME_) prefix=grade;
by ID;
var grade;
run;
You're missing a variable from your program. Where do the numbers like 88, 82, and 89 come from?
Whatever the name of the variable is, it should go in a VAR statement within PROC TRANSPOSE.
The ID statement must refer to an existing variable, in this case GRADE.
sorry I was inconsistent with describing it...the values 88, 90 etc are the values for the grade
I looked at tutorials and tried it and it just wouldn't work. It's not even multiple variables and I can't seem to get it
PROC TRANSPOSE is not the easiest thing to learn. What you are looking for might be as simple as this:
proc transpose data=long out=wide (drop=_NAME_) prefix=grade;
by ID;
var grade;
run;
I had actually just entered this and it worked after trying so many combinations.
I was over-complicating something so simple.
Thanks!!
Transposing data tutorials:
Long to Wide:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/
https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/
You are referring to ID as grade1-grade3 which are not variables that exist. You need to refer just to grade.
See the first example in the first link above.
@SASnewbiee wrote:
Hello,
I am having trouble going from long to wide using Proc transpose.
It seems like it should be really simple but I'm not getting it correct:
Trying to go from:
ID grade
1 grade1
1 grade2
1 grade3
2 grade1
2 grade2
2 grade3
3 grade1
3 grade2
3 grade3
to:
ID grade1 grade2 grade3
1 88 82 892 76 87 90
3 99 94 89
I tried
**proc transpose from long to wide;
proc transpose data=long out=wide (drop=_NAME) prefix=grade;
by ID;
id grade1-grade3;
run;
Proc print data=wide;
title ' Transpose from Long to Wide';
run;
I have
1 | 99 (grade1) |
1 | 80 (grade2) |
1 | 78 (grade3) |
2 | 89 (grade1) |
2 | 76 (grade2) |
2 | 88 (grade3) |
I'm trying to get to:
ID | Grade1 | Grade2 | Grade |
1 | 99 | 80 | 78 |
| 2 | 89 | 76 | 88 |
| etc | |||
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.