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

Hello, this is the dataset I have available:

 

data Have;
input ID arrange_date :ddmmyy. datestamp :ddmmyy.;
format arrange_date datestamp ddmmyy10.;
datalines;
001 05/06/2020 01/06/2020
001 05/07/2020 01/06/2020
001 05/08/2020 01/06/2020
001 05/06/2020 02/06/2020
001 05/07/2020 02/06/2020
001 05/08/2020 02/06/2020
001 05/06/2020 03/06/2020
001 05/07/2020 03/06/2020
001 05/08/2020 03/06/2020

001 10/10/2020 03/10/2020 001 10/11/2020 03/10/2020 001 10/12/2020 03/10/2020 001 10/10/2020 04/10/2020 001 10/11/2020 04/10/2020 001 10/12/2020 04/10/2020

002 20/03/2020 10/03/2020 002 20/04/2020 10/03/2020 002 20/05/2020 10/03/2020 002 20/06/2020 10/03/2020 002 20/03/2020 11/03/2020 002 20/04/2020 11/03/2020 002 20/05/2020 11/03/2020 002 20/06/2020 11/03/2020; run;

 To clarify: 

-There are many client ID's.

-The second column refers to certain arranged dates when the client needs to perform an action. 

-The third column is the datestamp. 

-There is one row per client's arrangement date, per datestamp. As you can see, client 001 has two different "periods" in this table, one that goes from 05/06 and another that starts in 10/10.

 

I'm interested in keeping only the first unique occurrences of arrange_date. In this case it would look like this:

data Have;
input ID arrange_date :ddmmyy. datestamp :ddmmyy.;
format arrange_date datestamp ddmmyy10.;
datalines;
001 05/06/2020 01/06/2020
001 05/07/2020 01/06/2020
001 05/08/2020 01/06/2020

001 10/10/2020 03/10/2020
001 10/11/2020 03/10/2020
001 10/12/2020 03/10/2020

002 20/03/2020 10/03/2020
002 20/04/2020 10/03/2020
002 20/05/2020 10/03/2020
002 20/06/2020 10/03/2020

;
run;

As you can see, I only kept the first occurrence of each "arrange_date". 

I'm okay if it's done either in proc sql or a data step.

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Try

proc sort data=have out=want nodupkey;
   by id arrange_date;
run;

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

Try

proc sort data=have out=want nodupkey;
   by id arrange_date;
run;
catkat96
Obsidian | Level 7
yes, perfect! I was juggling more complex things in my mind but sometimes simpler is better!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 1660 views
  • 0 likes
  • 2 in conversation