- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello. I have a data set as following below.
ID Year Var1
1 1999 aa
2 1998 ab
2 1998 ac
2 1998 ab
2 1998 ac
3 1998 ad
The red lines are the same and the blue line are the same. If all three variables (ID, year and Var1) are the same, then retain the first one and delete the duplicated one.
The data set following below is what I expect
ID Year Var1
1 1999 aa
2 1998 ab
2 1998 ac
3 1998 ad
What code do I need? Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input ID Year Var1 $;
cards;
1 1999 aa
2 1998 ab
2 1998 ac
2 1998 ab
2 1998 ac
3 1998 ad
;
proc sql;
create table want as
select distinct *
from have;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input ID Year Var1 $;
cards;
1 1999 aa
2 1998 ab
2 1998 ac
2 1998 ab
2 1998 ac
3 1998 ad
;
proc sql;
create table want as
select distinct *
from have;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.It works well!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If I have 4 variables and want to retain the first one for those that are same for the three variables (ID, Year and Var1), what code do I need? I have not used SQL before and am still learning it. Thanks for your patience.
original Data set:
ID Year Var1 Var2
1 1999 aa ba
2 1998 ab bb
2 1998 ac bc
2 1998 ab bd
2 1998 ac be
3 1998 ad bf
Expected Data set:
ID Year Var1 Var2
1 1999 aa ba
2 1998 ab bb
2 1998 ac bc
3 1998 ad bf
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
input ID Year var1 $ Var2 $;
cards;
1 1999 aa ba
2 1998 ab bb
2 1998 ac bc
2 1998 ab bd
2 1998 ac be
3 1998 ad bf
;
proc sort data=have out=want nodupkey;
by id year var1;
run;
Just a simple proc sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much! Have a great thanksgiving day!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You too. Enjoy black friday shopping