BookmarkSubscribeRSS Feed
harsh0404
Fluorite | Level 6

tablea.PNGanswerlookingfor.PNG

 

So I have 10 million rows in a dataset and this is what data looks like (on left). consists of decile ,a category and profits. 

Now I need to create something on my right. Decile as rows, category as column and mean of profits as the values in the table. So for example - all the values that are in decile 1 and category a, their mean profit is 300 dollars.

3 REPLIES 3
hashman
Ammonite | Level 13

@harsh0404:

Methinks this is what proc TRANSPOSE is designed for:

data have ;                                        
  input decile category :$1.profit ;               
  cards ;                                          
1  a  300                                          
2  h  500                                          
4  t  670                                          
6  u  540                                          
8  q  109                                          
1  q  409                                          
9  r  870                                          
;                                                  
run ;                                              
                                                   
proc sort data = have out = haves ;                
  by decile ;                                      
run ;                                              
                                                   
proc transpose data = haves out = want (drop = _:) ;
  by decile ;                                      
  id category ;                                    
  var profit ;                                     
run ;                                              

Kind regards

Paul D. 

ballardw
Super User

Or possibly as simple as:

 

proc tabulate data=have;
   class decile category;
   var profit;
   table decile=' ', 
         category*profit=''*mean=''
         /misstext=' ' box=decile
   ;
run;
hashman
Ammonite | Level 13

@ballardw:

Had thought of, too (love proc TAB). If the OP needs a report rather than a data set, it's picture perfect. 

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