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!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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