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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

3 REPLIES 3
Lijuu
Obsidian | Level 7
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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:.

Lijuu
Obsidian | Level 7
Dear! Thank you. I will do after this time for the point what you advice me to do!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 479 views
  • 1 like
  • 2 in conversation