BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BCNAV
Quartz | Level 8

This is a bit of a weird request....I have some data on aircraft flights that I need to break out depending on how many times they appear in a group. The group is identified as follows:

 

daily_grouping
104042452
104042452
104042452
104042452
104042452
104042452
104042453
104042454
104042455
104042455
104042456
104042456
104042456

 

There are other variables as well, but the daily_grouping is the one to key in on. Here is what I would like:

 

1. If a daily_grouping number appears only once, it should be removed.

2. If a daily_grouping number appears more than once, then the first instance should be removed and n-1 should remain.

 

This means that in the example above the result would be:

 

daily_grouping
104042452
104042452
104042452
104042452
104042452
104042455
104042456
104042456

 

Any help would be appreciated! Not sure if multiple steps are needed.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
data have;
input daily_grouping :$10.;
datalines;
104042452
104042452
104042452
104042452
104042452
104042452
104042453
104042454
104042455
104042455
104042456
104042456
104042456
;

data want;
   set have;
   by daily_grouping;
   if not first.daily_grouping;
run;

View solution in original post

4 REPLIES 4
ballardw
Super User
data have;
input daily_grouping :$10.;
datalines;
104042452
104042452
104042452
104042452
104042452
104042452
104042453
104042454
104042455
104042455
104042456
104042456
104042456
;

data want;
   set have;
   by daily_grouping;
   if not first.daily_grouping;
run;
andreas_lds
Jade | Level 19
Untested code:

data want;
set have;
by daily_grouping;
if not first.daily_grouping;
run;
BCNAV
Quartz | Level 8
thanks all!
Ksharp
Super User
data have;
input daily_grouping :$10.;
datalines;
104042452
104042452
104042452
104042452
104042452
104042452
104042453
104042454
104042455
104042455
104042456
104042456
104042456
;

proc sort data=have dupout=want nodupkey;
by daily_grouping ;
run;

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1389 views
  • 0 likes
  • 4 in conversation