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

Hi Everyone,

My data like this:

ID  CD

1     3

1     4

1     5

2     6

2     7

2     8

How do I change data like this:

ID       CD1          CD2           CD3        

1           3                4               5

2           6                7               8

Thanks in Advance.

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14
Hi,
You can use proc transpose:

Proc transpose data=have out=want (drop=_:) prefix=CD;
Var CD;
By ID;
Run;

View solution in original post

6 REPLIES 6
ed_sas_member
Meteorite | Level 14
Hi,
You can use proc transpose:

Proc transpose data=have out=want (drop=_:) prefix=CD;
Var CD;
By ID;
Run;
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/

This is called a transpose and you can use PROC TRANSPOSE. 

If you want just a report, PROC FREQ or TABULATE will do it.

peiy5920
Calcite | Level 5
Thank you for your link.
peiy5920
Calcite | Level 5

Hi,

My data like this:

ID  CD  time treatment

1     3       1        2

1     4       2        2

1     5       3        2

2     6       1        4

2     7       2        4

2     8       3        4

How do I change data like this:

ID       CD1          CD2           CD3        

1           3                4               5

2           6                7               8

From your link, I wrote my code:

proc transpose data=AIDS  out= Output (drop = _NAME_) prefix=CD_;
id time;
var CD;
by ID;
run;

If I add another variable treatment in the data, like this

ID       CD1          CD2           CD3        treatment

1           3                4               5                2

2           6                7               8                4

What should I do? I appreciate your help.

 

Reeza
Super User

Add the variable to the BY statement or a COPY statement. 

peiy5920
Calcite | Level 5
Thanks a lot!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1185 views
  • 0 likes
  • 3 in conversation