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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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