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

Hi,

 

I am trying to reformat a really large dataset for better analysis

 

what I have  
Year ManagerSales (#) 
2015Alan360 
2015James190 
2015Elena220 
2015McCarthy470 
2016Alan387 
2016James202 
2016Elena250 
2016McCarthy515 
2017Alan  
2017James  
2017Elena  
2017McCarthy  
    
what I want  
Manager201520162017
Alan360387 
James190202 
Elena220250 
McCarthy470515 

 

Thank you,

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

That's from long to wide. A standard proc transpose is your easiest solution.

 

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/


@michokwu wrote:

Hi,

 

I am trying to reformat a really large dataset for better analysis

 

what I have    
Year  Manager Sales (#)  
2015 Alan 360  
2015 James 190  
2015 Elena 220  
2015 McCarthy 470  
2016 Alan 387  
2016 James 202  
2016 Elena 250  
2016 McCarthy 515  
2017 Alan    
2017 James    
2017 Elena    
2017 McCarthy    
       
what I want    
Manager 2015 2016 2017
Alan 360 387  
James 190 202  
Elena 220 250  
McCarthy 470 515  

 

Thank you,




View solution in original post

6 REPLIES 6
Reeza
Super User

That's from long to wide. A standard proc transpose is your easiest solution.

 

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/


@michokwu wrote:

Hi,

 

I am trying to reformat a really large dataset for better analysis

 

what I have    
Year  Manager Sales (#)  
2015 Alan 360  
2015 James 190  
2015 Elena 220  
2015 McCarthy 470  
2016 Alan 387  
2016 James 202  
2016 Elena 250  
2016 McCarthy 515  
2017 Alan    
2017 James    
2017 Elena    
2017 McCarthy    
       
what I want    
Manager 2015 2016 2017
Alan 360 387  
James 190 202  
Elena 220 250  
McCarthy 470 515  

 

Thank you,




michokwu
Quartz | Level 8

Yes, long to wide. Thank you

Astounding
PROC Star

Your current form of the data will support most analyses.  What type of analysis would you want to perform, where you need to transpose the data?

michokwu
Quartz | Level 8

Need to observe trends over time. The transpose works. Thank you

Reeza
Super User

To graph that data you would want it in the current form. It's also easier to calculate month over month/year over year/year to date calculations in the long format. 

 

The wide format is really only useful for appearances in my experience. 

 


@michokwu wrote:

Need to observe trends over time. The transpose works. Thank you


 

novinosrin
Tourmaline | Level 20
data have;
infile cards expandtabs truncover;
input Year 	Manager $	Sales 	 ;
cards;
2015	Alan	360	 
2015	James	190	 
2015	Elena	220	 
2015	McCarthy	470	 
2016	Alan	387	 
2016	James	202	 
2016	Elena	250	 
2016	McCarthy	515	 
2017	Alan	 	 
2017	James	 	 
2017	Elena	 	 
2017	McCarthy	 
;
proc sort data=have out=_have;
by manager year;
run;
proc transpose data=_have out=want(drop=_name_) prefix=Year_;
by manager;
var sales;
id year;
run;

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
  • 6 replies
  • 799 views
  • 1 like
  • 4 in conversation