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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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