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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

6 REPLIES 6
Astounding
PROC Star

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.

SASnewbiee
Fluorite | Level 6

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

Astounding
PROC Star

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;
SASnewbiee
Fluorite | Level 6

I had actually just entered this and it worked after trying so many combinations.

I was over-complicating something so simple.

 

Thanks!!

Reeza
Super User

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          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;

 




SASnewbiee
Fluorite | Level 6

 

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

2897688
etc   
    
    
    

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

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