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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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