Hi all,
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!
Use a SQL query - this will work in SAS but isn't ANSI SQL, so won't work in other SQL systems.
proc sql;
create table want as
select *, count(id) as Num_ID
from have
group by ID
order by ID;
quit;
Thanks so much, it worked!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.