03-03-2015 06:38 PM
I have a set of survey data which gives each person's personal identification code (lets call this variable ID for now). Most people were called more than once, and each time they were called, they are added as a separate entry in the data set, therefore there are many duplicate personal identification codes, but with different values for other variables (which are the questions they were asked).
I collapsed the ID variable so each unique id only shows up once in the data set (I am creating new summary variables and dropping all other variables in the original data set). I would like to create a variable that sums the number of times the ID was duplicated to show the number of times the person was called. Does anyone know how to do this?
Basically I want this new variable to be what a proc freq on the ID variable would reveal, and I will create it before I collapse the ID variable.
I can't use first.ID/last.ID because it requires me to collapse the ID variable first.
Thanks in advance for the help!
03-03-2015 07:24 PM
Use a SQL query - this will work in SAS but isn't ANSI SQL, so won't work in other SQL systems.
create table want as
select *, count(id) as Num_ID
group by ID
order by ID;