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 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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