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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 714 views
  • 1 like
  • 3 in conversation