/ Published in: SAS
                    
                                        
Determine how many observations there are in each BY-Group by using BY-Group processing.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/* Create sample data */
data old;
input state $ accttot;
datalines;
ca 7000
ca 6500
ca 5800
nc 4800
nc 3640
sc 3520
va 4490
va 8700
va 2850
va 1111
;
proc sort data=old;
by state;
run;
/* To get the number of observations in each group of states, start */
/* a counter on the first observation of each BY-Group. The last */
/* observation in the BY-Group contains the total number of */
/* observations and is output to the data set. */
data new;
set old (drop= accttot);
by state;
if first.state then count=0;
count+1;
if last.state then output;
run;
proc print;
run;
/* Alternative approach using PROC FREQ to generate the same output */
proc freq;
tables state / out=new(drop=percent);
run;
URL: http://support.sas.com/kb/24/595.html
Comments
 Subscribe to comments
                    Subscribe to comments
                
                