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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1067 views
  • 0 likes
  • 2 in conversation