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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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