BookmarkSubscribeRSS Feed
sasphd
Lapis Lazuli | Level 10

hello 

Have

secid   01-2020  02-2020 03-2020

1            0.3            0.2          0.6

2               0.25        0.68       0.95

want

secid  caldt           mret

1         01-2020     0.3

1          02-2020       0.2

1         03-2020      0.6

2        01-2020       0.25

2          02-2020      0.68

2         03-2020      0.95

 

3 REPLIES 3
Reeza
Super User

Have you tried a PROC TRANSPOSE? If so, please show your code.
Your variable names are not valid SAS names so you may want to consider providing sample data that's similar to your actual data structure.

 

Transposing data tutorials:
Wide to Long:
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/

https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/


@sasphd wrote:

hello 

Have

secid   01-2020  02-2020 03-2020

1            0.3            0.2          0.6

2               0.25        0.68       0.95

want

secid  caldt           mret

1         01-2020     0.3

1          02-2020       0.2

1         03-2020      0.6

2        01-2020       0.25

2          02-2020      0.68

2         03-2020      0.95

 


 

 

sasphd
Lapis Lazuli | Level 10

I do this but it does not work

 

PROC TRANSPOSE
DATA=have;
OUT=want ;
by secid;
RUN;

Reeza
Super User

You didn't specify any variables in that list. Try explicitly listing the variables you want to transpose and include them in the VAR statement.

Additionally, an array method in a data step may be simpler for you to code, update and understand and may be worth a shot. The tutorial in my first post has the details.

 

Also, please explain what " does not work" means. That could mean anything from your SAS installation crashed to errors in the log to it worked but you checked the wrong output file or expected results in the results pane which does not happen. And include your log, especially if there are warnings or errors.

 


@sasphd wrote:

I do this but it does not work

 

PROC TRANSPOSE
DATA=have;
OUT=want ;
by secid;
RUN;


 

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 184 views
  • 0 likes
  • 2 in conversation