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

Hi everyone, 

 

I need help please with turning observations into variables. Here's an example of what I have

 

ID                   Date                     Event Date                Return

101           01/01/2020                01/01/2020                 0.02

101           02/01/2020                01/01/2020                 0.0015

101           03/01/2020                01/01/2020                 0.001

102           01/01/2020                01/01/2020                 0.0222

102           02/01/2020                01/01/2020                 0.001

102           03/01/2020                01/01/2020                 0.0015

103           01/01/2020                01/01/2020                 0.003

103           02/01/2020                01/01/2020                 0.03

103           03/01/2020                01/01/2020                 0.035

 

And here's what I want: 

 

Date                           Event date            101         102             103

01/01/2020                01/01/2020           0.02        0.0222         0.003

02/01/2020                01/01/2020         0.0015       0.001          0.03

03/01/2020                01/01/2020         0.001        0.0015         0.035

 

Hope that makes sense and thank you in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
sustagens
Pyrite | Level 9

You need to do a transpose, but sort it first.

 

proc sort 
data=have;
by date event_date;
run;

proc transpose 
data=have;
out=want;
by date event_date; /*your group by variables*/
id ID; /*the new variable names*/
var return; /*variable to be "transposed"*/
run;
quit;

View solution in original post

2 REPLIES 2
sustagens
Pyrite | Level 9

You need to do a transpose, but sort it first.

 

proc sort 
data=have;
by date event_date;
run;

proc transpose 
data=have;
out=want;
by date event_date; /*your group by variables*/
id ID; /*the new variable names*/
var return; /*variable to be "transposed"*/
run;
quit;
Antoine44
Fluorite | Level 6
Awesome, that worked! Thanks 🙂

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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