BookmarkSubscribeRSS Feed
InfoGuru
Calcite | Level 5
This is a very stupid question for which i seem to have lost my code and forgotten the rest. if someone can help me great.
To uniquely count rows in a data set with duplicate primary keys e.g. Three rows with data with the same primary key and i want to count them 1,2,3.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
DATA step logic (sorted input file) using a BY statement and IF FIRST._varname_ logic to increment a user SAS variable for all non-FIRST conditions and assign a value of 1 for the FIRST condition.

* input to next DATA step is sorted on _primary_key_variables_. ;
DATA _output2_;
set _input1_;
BY _primary_key_variables_;
IF FIRST._your_last_break_variable_ THEN DUPCOUNT = 0;
IF NOT (FIRST._your_last_break_variable_ AND LAST._your_last_break_variable_) THEN DUPCOUNT + 1;
RUN;

Scott Barry
SBBWorks, Inc.
mftuchman
Quartz | Level 8
Another method that may work if you just want the counts of each duplicate key tuple is to use PROC FREQ with the LIST option.

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
  • 687 views
  • 0 likes
  • 3 in conversation