BookmarkSubscribeRSS Feed
summerkk
Calcite | Level 5

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!

2 REPLIES 2
Reeza
Super User

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;

summerkk
Calcite | Level 5

Thanks so much, it worked!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 8340 views
  • 1 like
  • 2 in conversation