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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.