03-02-2017 02:34 AM
Each unique ID have many different rows of addresses, I want a program to select for each unqiue ID any 3 rows of addressses.
Example of dataset:
03-02-2017 03:42 AM
If the data is sorted as per your example, use data step with BY ID, and use a counter that is re-initiated for each first.ID.
Use explicit output when the counter is <= 3.
03-02-2017 04:14 AM
Just a slight alteration of @LinusH answer uses lag to decide if to output or not (saves a variable and line of code):
data have; input id address $; datalines; 1 A 1 B 1 C 2 HH 2 KK 2 NN 2 MM ; run; data want; set have; by id; if first.id or lag(first.id) or lag2(first.id) then output; run;
03-02-2017 06:01 AM
data have; input id address $; datalines; 1 A 1 B 1 C 2 HH 2 KK 2 NN 2 MM ; run; proc surveyselect data=have out=want sampsize=3; strata id; run;