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

Hey everyone.

Need help with transposing data from long to wide. Here is the data I have:

pump_numberadj_cycle_numbercycle_up_slopecycle_down_slopetarget
1111843.61-3894.3fail
1122055.37-4053.6fail
1132154.83-4212.41fail
1212132.037-2704.71pass
1222139.293-2855.92pass
1232232.83-4663.27pass

 

This is what I need:

pump_numbercycle_up_slope1cycle_up_slope2cycle_up_slope3cycle_down_slope1cycle_down_slope2cycle_down_slope3target
111843.612055.372154.83-3894.3-4053.6-4212.41fail
122132.0372139.2932232.83-2704.71-2855.92-4663.27pass

 

Can you help?

Thanks!

Dipu

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input pump_number	adj_cycle_number	cycle_up_slope	cycle_down_slope	target $;
cards;
11	1	1843.61	-3894.3	fail
11	2	2055.37	-4053.6	fail
11	3	2154.83	-4212.41	fail
12	1	2132.037	-2704.71	pass
12	2	2139.293	-2855.92	pass
12	3	2232.83	-4663.27	pass
;

proc transpose data=have out=_have;
 by pump_number adj_cycle_number target;
 var cycle_up_slope	cycle_down_slope;
run;

proc transpose data=_have out=want(drop=_name_);
 by pump_number target;
 var col1;
 id _name_ adj_cycle_number;
run;

View solution in original post

4 REPLIES 4
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/

Both of these have examples for exactly your situation. 

The data step lets you do it in one step, the transpose is multiple steps but easier to understand for beginners in my opinion. 

 

If you have issues getting it to work feel free to post your code. 

 


@DipuRahman wrote:

Hey everyone.

Need help with transposing data from long to wide. Here is the data I have:

pump_number adj_cycle_number cycle_up_slope cycle_down_slope target
11 1 1843.61 -3894.3 fail
11 2 2055.37 -4053.6 fail
11 3 2154.83 -4212.41 fail
12 1 2132.037 -2704.71 pass
12 2 2139.293 -2855.92 pass
12 3 2232.83 -4663.27 pass

 

This is what I need:

pump_number cycle_up_slope1 cycle_up_slope2 cycle_up_slope3 cycle_down_slope1 cycle_down_slope2 cycle_down_slope3 target
11 1843.61 2055.37 2154.83 -3894.3 -4053.6 -4212.41 fail
12 2132.037 2139.293 2232.83 -2704.71 -2855.92 -4663.27 pass

 

Can you help?

Thanks!

Dipu


 

DipuRahman
Calcite | Level 5
@Reeza Thank you.
novinosrin
Tourmaline | Level 20

data have;
input pump_number	adj_cycle_number	cycle_up_slope	cycle_down_slope	target $;
cards;
11	1	1843.61	-3894.3	fail
11	2	2055.37	-4053.6	fail
11	3	2154.83	-4212.41	fail
12	1	2132.037	-2704.71	pass
12	2	2139.293	-2855.92	pass
12	3	2232.83	-4663.27	pass
;

proc transpose data=have out=_have;
 by pump_number adj_cycle_number target;
 var cycle_up_slope	cycle_down_slope;
run;

proc transpose data=_have out=want(drop=_name_);
 by pump_number target;
 var col1;
 id _name_ adj_cycle_number;
run;
DipuRahman
Calcite | Level 5

Thanks you

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 832 views
  • 0 likes
  • 3 in conversation