Change data format

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Change data format

How can i change a data in wide format for the following data format by source.

ID   source  cp      resp

1          a      1        0.1

1          a      2        0.5

1          b      1        0.3

1          b      2        0.2

2          a      1        0.15

2          a      2        0.7

2          b      1        0.8

2          b      2        0.4

into a format 

ID    cp    resp_a  resp_b

1      1        0.1       0.5

1      2        0.3      0.2

2      1        0.15    0.7

2      2        0.8      0.4

 

Thank you!


Accepted Solutions
Solution
‎04-30-2018 04:18 AM
Super User
Super User
Posts: 9,599

Re: Change data format

You can use proc tranpose for that, very simple:

proc tranpose data=have out=want prefix=resp_;
  by id cp;
  var resp;
  id source;
run;

Note assumes sorted by the by variables.  Post test data in the form of a datastep next time.

 

Also, unless this is for a report output, it is really not recommended to program in this way, it will make all your program from that point on much harder, and you have increased the difficulty even more by affixing a character as the end, thus you will struggle to even use lists and such like, e.g. var1, var2, can be a list of var:.

View solution in original post


All Replies
Contributor
Posts: 22

Re: Change data format

sorry ! the format should be a format below:

ID cp resp_a resp_b

1 1 0.1 0.3

1 2 0.5 0.2

2 1 0.15 0.8

2 2 0.7 0.4
Solution
‎04-30-2018 04:18 AM
Super User
Super User
Posts: 9,599

Re: Change data format

You can use proc tranpose for that, very simple:

proc tranpose data=have out=want prefix=resp_;
  by id cp;
  var resp;
  id source;
run;

Note assumes sorted by the by variables.  Post test data in the form of a datastep next time.

 

Also, unless this is for a report output, it is really not recommended to program in this way, it will make all your program from that point on much harder, and you have increased the difficulty even more by affixing a character as the end, thus you will struggle to even use lists and such like, e.g. var1, var2, can be a list of var:.

Contributor
Posts: 22

Re: Change data format

Dear! Thank you. I will do after this time for the point what you advice me to do!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 145 views
  • 1 like
  • 2 in conversation