group by in sas

sas

Solution

Try this:

DATA Have; 
 input id ; 
 datalines;
 1
 2
 2
 3
 4
 4
 4
 5 
 ;

Proc Sort data=Have;
 by ID;
run;

Data Want;
 Set Have;
 By ID;
 If first.ID then Count=0;
 Count+1;
 If Last.ID then Output;
Run;

Problem

I've the below dataset as input ``` ID -- 1 2 2 3 4 4 4 5 ``` And need a new dataset as below ``` ID count of ID -- ----------- 1 1 2 2 3 1 4 3 5 1 ``` Could you please tell how to do this in SAS wihtout using PROC SQL?

Original source