BookmarkSubscribeRSS Feed
yichentian226
Obsidian | Level 7

Hi community!

 

I have a question regarding below example:

 

date              userid        factor 

8/21/2020     736ksls      text

11/20/2020   736ksls      text

02/07/2019   blea282     text

10/28/2020   blea282     text

 Can anyone provide a solution to only keep the records ( when userid and factor are the same) with a later date? Thanks a lot from a beginner!

 

In this example I only want to keep 2 records: 

date              userid        factor 

11/20/2020   736ksls      text

10/28/2020   blea282     text

 

4 REPLIES 4
yichentian226
Obsidian | Level 7

I am answering myself hahah 

proc sql;

create table xx as

select * from sample;

group by userid 

having date_new=max(date);

quit;

 

Please feel free to share any thoughts you have 🙂  

novinosrin
Tourmaline | Level 20


data have;
input date :mmddyy10.             userid  $      factor  $;
format date mmddyy10.;
cards;
8/21/2020     736ksls      text

11/20/2020   736ksls      text

02/07/2019   blea282     text

10/28/2020   blea282     text
;

data want;
 set have;
 by userid factor notsorted;
 if last.factor;
run;
/*or SQL*/
proc sql;
 create table want as
 select *
 from have
 group by userid,factor
 having max(date)=date;
quit;
yeji6144
Calcite | Level 5

You can try:

IF LAST.userid=1 THEN DO;
OUTPUT;

ballardw
Super User

@yeji6144 wrote:

You can try:

IF LAST.userid=1 THEN DO;
OUTPUT;


Better End; that Do;

or just:

 

If last.userid;

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
  • 4 replies
  • 1201 views
  • 1 like
  • 4 in conversation