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
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 🙂
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;
You can try:
IF LAST.userid=1 THEN DO;
OUTPUT;
@yeji6144 wrote:
You can try:
IF LAST.userid=1 THEN DO;
OUTPUT;
Better End; that Do;
or just:
If last.userid;
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!
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.
Ready to level-up your skills? Choose your own adventure.