Hello!
I have a dataset that is sorted in id, years, months, day and city based for each individual purchase. I want to sorted out duplicates that have the same id, year, month and day but different city as shown in dataset 'want'.
data have;
;
input ID$ Year$ month$ Day$ City$;
datalines;
1 2017 Jan Monday Rome
1 2017 Jan Monday Paris
1 2018 Jan Tuesday Rome
1 2018 Jan Tuesday Rome
2 2015 Feb Wednesday Rome
2 2015 Feb Wednesday Paris
2 2018 Feb Friday Rome
2 2018 Feb Friday Rome
3 2015 Apr Wednesday Rome
3 2015 Apr Wednesday Paris
3 2018 Apr Friday Rome
3 2018 Apr Friday Rome
;
run;
data want;
;
input ID$ Year$ month$ Day$ City$;
datalines;
1 2017 Jan Monday Rome
1 2017 Jan Monday Paris
2 2015 Feb Wednesday Rome
2 2015 Feb Wednesday Paris
3 2015 Apr Wednesday Rome
3 2015 Apr Wednesday Paris
;
run;
data want;
set have;
by id year month day city;
if first.city and last.city;
run;
Your data is year/month/day of week instead of year/month/day of month? That really doesn't make sense to me.
data want;
set have;
by id year month day city;
if first.city and last.city;
run;
Your data is year/month/day of week instead of year/month/day of month? That really doesn't make sense to me.
data have;; input ID$ Year$ month$ Day$ City$; datalines; 1 2017 Jan Monday Rome 1 2017 Jan Monday Paris 1 2018 Jan Tuesday Rome 1 2018 Jan Tuesday Rome 2 2015 Feb Wednesday Rome 2 2015 Feb Wednesday Paris 2 2018 Feb Friday Rome 2 2018 Feb Friday Rome 3 2015 Apr Wednesday Rome 3 2015 Apr Wednesday Paris 3 2018 Apr Friday Rome 3 2018 Apr Friday Rome ; run; proc sort data=have out=duplicate nouniquekey uniqueout=want; by _all_; run;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.